I need a Xpath query to find a XML file with certain nodes. The nodes are located at different levels in the XML file, under different parents. So, it would be like if I want to recover a file like the one below using the nodes "author" and "ref year =1999".
<FILE>
<header>
<author> X </author>
</header>
<text>
<type>
<ref year="1999">
</type>
</text>
</FILE>
The only difference is that the XML I'm using have a much more complex structure, so it would be ideal if I could use a "//" to find the nodes anywhere, instead of using the exact path. I can't use the | operator to join the two nodes, because I want to find the files which satisfy both conditions and not only one.
Thanks!
This XPath,
will select
FILEelements anywhere in the document that meet the conditions in the predicate.Use
orrather thanandif you want a disjunctive predicate. (Note that|is used to concatenate node sets.) Combinations ofand,or, andnot()can be used to express full boolean expressions in the predicate.If the structure beneath
FILEitself varies, you can use.//to "skip over" the variations. For example,will disregard the path between
FILEand each ofauthorandref/@year.