XPath - Limiting Parent

M

Michael Doyle

Hi,

Using XPath, I want to get all elements FOO which are not children of
BAR.

What i have done in this instance is:
//FOO[name(..)!='BAR']

this only works when BAR is immediately below FOO, it's also kinda
ugly.
Is there a better way?

Thanks,
Micky
 
M

Martin Honnen

Michael said:
Using XPath, I want to get all elements FOO which are not children of
BAR.

What i have done in this instance is:
//FOO[name(..)!='BAR']

You do not need name checks, you can simply do
//FOO[not(parent::BAR)]
this only works when BAR is immediately below FOO,

That is what you want if your description above is correct: FOO elements
which are not children of BAR.
If you want FOO elements which are not descendants of BAR then you can use
//FOO[not(ancestor::BAR)]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,851
Latest member
CliftonCor

Latest Threads

Top