代码之家  ›  专栏  ›  技术社区  ›  Marcus S. Zarra

XPath查询搜索具有特定文本的元素

  •  17
  • Marcus S. Zarra  · 技术社区  · 16 年前

    给定以下XML结构

    <html>
      <body>
        <div>
          <span>Test: Text2</span>
        </div>
        <div>
          <span>Test: Text3</span>
        </div>
        <div>
          <span>Test: Text5</span>
        </div>
      </body>
    </html>
    

    找到任何 span 以开头的文本 Test ?

    2 回复  |  直到 10 年前
        2
  •  4
  •   A.D. Ashraf Farhan    12 年前

    有效选项还包括:

    //span[contains(.,'Test')]