[英]How do I select multiple sets of attributes within an XML document using XPath?
I am having trouble constructing a single XPath statement to return two different sets of attributes. 我在构造单个XPath语句以返回两组不同的属性时遇到问题。
For example take the following XML document: 例如,请使用以下XML文档:
<root>
<line name="one" alpha="a1" beta="b1"/>
<line name="two" alpha="a2" beta="b2"/>
<line name="three" alpha="a3" beta="b3"/>
</root>
If I use the following XPath statement: 如果我使用以下XPath语句:
//@alpha
It yields the following attribute set: 它产生以下属性集:
alpha="a1"
alpha="a2"
alpha="a3"
What statement do I use to yield the following attribute set: 我使用什么语句来产生以下属性集:
alpha="a1"
alpha="a2"
alpha="a3"
beta="b1"
beta="b2"
beta="b3"
By using the |
通过使用|
operator in an XPath expression you can select several paths: 在XPath表达式中,您可以选择多个路径:
//@alpha | //@beta
//@*[name()='alpha' or name()='beta']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.