选择其属性以XPath中的某些内容开头的元素 [英] Selecting elements whose attribute begins with something in XPath
本文介绍了选择其属性以XPath中的某些内容开头的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题所示,是否可以在XPath中选择仅以某个字符串开头的元素,但可能不会以相同的结尾?
例如有3个定位元素:
< a href =buy.php / onething>< / a><<< ; a href =buy.php / twothing>< / a>< a href =sell.php / anotherthing>< / a>
我只想获取以'buy.php /'开头的锚元素。我不认为以下内容会起作用,是否会这样:
getByXPath(// a [@ href ='buy。 php /'])
如何做到这一点? <在这里,你可以找到一些有用的信息,这些信息可以帮助你解决问题。
http:// www.zvon.org/xxl/XSLTreference/Output/function_starts-with.html
As the title says, is it possible to select elements in XPath that only begin with a certain string, but perhaps do not end with the same?
For example there are 3 anchor elements:
<a href="buy.php/onething"></a><a href="buy.php/twothing"></a><a href="sell.php/anotherthing"></a>
I only want to get anchor elements that begin with 'buy.php/'. I don't think the following will work, will it:
getByXPath("//a[@href='buy.php/']")
How can I do this?
解决方案
//a[starts-with(@href, 'buy.php/')]
http://www.zvon.org/xxl/XSLTreference/Output/function_starts-with.html
这篇关于选择其属性以XPath中的某些内容开头的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文