Single xpath expression to get some attributes
-
09-10-2019 - |
문제
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
?
해결책
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.
다른 팁
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 '
This will select all id
attribute nodes that have the value 7:
//*/@id[. = '7']
제휴하지 않습니다 StackOverflow