XPath - Limiting Parent

Discussion in 'XML' started by Michael Doyle, Jan 9, 2006.

  1. 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
     
    Michael Doyle, Jan 9, 2006
    #1
    1. Advertisements

  2. Michael Doyle wrote:

    > 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)]

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 9, 2006
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,298
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    8,164
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    762
  4. goog
    Replies:
    0
    Views:
    683
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    2,105
    Richard Tobin
    Nov 13, 2004
  6. Replies:
    4
    Views:
    1,006
    Joseph Kesselman
    Aug 10, 2006
  7. Replies:
    3
    Views:
    832
  8. Ian Wilson
    Replies:
    2
    Views:
    680
    Ian Wilson
    Jul 26, 2007
Loading...