18

给定以下 XML 结构

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

span查找任何以 开头的文本的最佳 XPath 查询是什么Test

4

2 回答 2

24
//span[starts-with(.,'Test')]


参考:

http://www.w3.org/TR/xpath/#function-starts-with

https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/starts-with

于 2008-09-29T04:20:38.050 回答
4

有效的选项也是:

//span[contains(.,'Test')]
于 2012-11-15T11:49:20.593 回答