문제

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']
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top