给定以下的XML结构
<html>
<body>
<div>
<span>Test: Text2</span>
</div>
<div>
<span>Test: Text3</span>
</div>
<div>
<span>Test: Text5</span>
</div>
</body>
</html>
如何使用XPath查询定位任何带有以Test
开头的文本的 span
元素?
//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')]
//span[starts-with(normalize-space(.), 'Test')]
。 - mlissner