Brian Myers Brian Myers - 9 months ago 36
Java Question

In xPath, how do you select all nodes not matching a subset?

I'm trying to grab a large set of xml nodes all at the same level (who's element names are all different) while excluding a certain subset of nodes. For example:


so I want an xPath expression to give me the spam eggs and toast node list while excluding the foo, bar and baz nodes. I know the nodes I want to exclude ahead of time but have no clue what nodes will be left over.


Combine three Xpathes

/root/spam | /root/eggs | /root/toast

Or write the same in different way

/root/*[contains("spam|eggs|toast", name())]


To exclude a set of nodes spam, eggs and toast

/root/*[not(contains("spam|eggs|toast", name()))]