How to select nodes whose parent has a specific attribute

Discussion in 'XML' started by bearclaws, Feb 28, 2005.

  1. bearclaws

    bearclaws Guest

    I want to select certain nodes from an XML file whose parent nodes
    contain a particular attribute id.

    For instance, here's a sample XML file:

    <AAA>
    <BBB id="111">text
    <CCC>text</CCC>
    </BBB>
    <BBB id="222">
    <CCC>text</CCC>
    </BBB>
    </AAA>

    ....and I want to loop through "AAA" and get all "CCC" nodes whose
    parents id is "111".

    How do I do this?

    Thanks,
    BC
     
    bearclaws, Feb 28, 2005
    #1
    1. Advertising

  2. bearclaws wrote:

    > I want to select certain nodes from an XML file whose parent nodes
    > contain a particular attribute id.
    >
    > For instance, here's a sample XML file:
    >
    > <AAA>
    > <BBB id="111">text
    > <CCC>text</CCC>
    > </BBB>
    > <BBB id="222">
    > <CCC>text</CCC>
    > </BBB>
    > </AAA>
    >
    > ...and I want to loop through "AAA" and get all "CCC" nodes whose
    > parents id is "111".


    XPath expression is
    /AAA/*[@id = '111']/CCC

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 28, 2005
    #2
    1. Advertising

  3. bearclaws

    bearclaws Guest

    Thanks but I left out the confusing part (sorry)...

    I want to loop through "AAA" and get all "CCC" nodes whose parents id
    is "111"...AND whose parents node value is "text".

    I'm not sure how to combine both an attribute and a value condition.

    Thoughts?
     
    bearclaws, Feb 28, 2005
    #3
  4. bearclaws wrote:


    > I want to loop through "AAA" and get all "CCC" nodes whose parents id
    > is "111"...AND whose parents node value is "text".


    Then perhaps the XPath expression is
    /AAA/*[@id = '111' and text()[1] = 'text']/CCC
    but there are many different views of what the node value is so I am not
    sure that will select what you are looking for.

    You might want to look at tutorials like
    <http://www.w3schools.com/xpath/default.asp>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 1, 2005
    #4
  5. bearclaws

    bearclaws Guest

    Many thanks! This worked great :)
    >>BC
     
    bearclaws, Mar 1, 2005
    #5
    1. Advertising

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. Michael Reiche
    Replies:
    3
    Views:
    10,890
    Michael Reiche
    Feb 5, 2004
  2. Duncan
    Replies:
    2
    Views:
    35,532
    Duncan
    Feb 9, 2006
  3. Dave Mathew
    Replies:
    0
    Views:
    870
    Dave Mathew
    Oct 6, 2008
  4. William  Krick
    Replies:
    4
    Views:
    14,559
    anntenna
    Mar 18, 2011
  5. Marek Mänd
    Replies:
    1
    Views:
    307
    Martin Honnen
    Feb 20, 2005
Loading...

Share This Page