XPath - Return current node without child nodes
Good day.
I hv the following XML for example and I tried to write a XPath query to return just the <AAA> and omit all the other child nodes (BBB and CCC and BBBBB) .
<AAA Name='aaa' ID='aaa'>
<BBB>bbbbbbbbbb</BBB>
<BBBBB>bbbbbbbbbbbbbbb</BBBBB>
<CCC>cccccccccc</CCC>
</AAA>
I tried //AAA/self::* but it still return the whole childnodes to me.
Any idea how to accomplish this ?
Thanks.
SonicWave :p
Re: XPath - Return current node without child nodes
I suppose XPath returns the AAA node, which has all other nodes as descendants, right? I cannot imagine that it returns a NodeSet that directly contains all the nodes.
Well, that's something you can't change with XPath. XPath only returns references to nodes, it can't change them. Returning a reference means that in order to have no child nodes, it must either return a copy or modify the referenced node. Neither makes sense.