My first post here – it’s a great site and I will certainly do my best to give back as much as I can.
I have seen different manifestations of this following question; however my attempts to resolve don’t appear to work.
Consider this simple tree:
<root>
<div>
<p>hello</p>
<p>hello2</p>
<p><span class="bad">hello3</span></p>
</div>
</root>
I would like to come up with an XPath expression that will select all child nodes of “div”, except for elements that have their “class” attribute equal to “bad”.
Here is what I have tried:
/root/div/node()[not (@class='bad')]
… However this doesn’t seem to work.
What am I missing here?
Cheers,
Isaac
When testing your XPath here with the provided XML document, the XPath seems to be indeed selecting all child nodes that do not have an attribute
class="bad"– these are all the<p>elements in the document.You will note that the only child node that has such an attribute is the
<span>, which indeed does not get selected.Are you expecting the
pnode surrounding yourspannot to be selected?