开发者

Single xpath expression to get some attributes

I have an XML document with some nodes开发者_开发技巧 like

<node name="xxx" id="xxx">

Can I use a single XPath expression to get all attribute nodes whose parent has also atrtribute @id = 7?


Use:

//@*[not(name()='id') and ../@id = 7]

this selects all non-id attributes whose parent has an id attribute with value the number 7. this will accept id='7' and id=' 7 '

//@*[not(name()='id') and ../@id = '7']

this selects all non-id attributes whose parent has an id attribute with value the string '7'. This will accept id='7' but not id=' 7 '


No. You will need to define which attribute to read out - one by one.

/node[@id=7]/@name 

will get the name

/node[@id=7]/@id

will get the id

etc.


This will select all id attribute nodes that have the value 7:

//*/@id[. = '7']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜