给定以下 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
?
//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
有效的选项也是:
//span[contains(.,'Test')]