Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top