XPath query help with getting parent nodes

Discussion in 'XML' started by mike@pmbtech.com, Jan 5, 2007.

  1. Guest

    Hello,
    I am new to XPATH and am having a hard time selecting some nodes.
    I want to select all the record nodes where Status = 'Unprocessed' or
    'Queued' (that part I can get) but additionally I only want the ones
    where the Field/Fieldname ='ChangeType' and Field/Value = 'SN'
    I have //ExtractInfo/Record[Status='UnProcessed' or
    Status='Queued']/Field[Fieldname='ChangeType' and Value='SN'] but that
    gets the field nodes, I need the record nodes.
    Below is a snippet of the abbreviated XML doc:
    <Extract>
    <ExtractInfo>
    <Status>UnProcessed</Status>
    <Record>
    <RecordNumber>1</RecordNumber>
    <Status>UnProcessed</Status>
    <Field>
    <Fieldname>ChangeType</Fieldname>
    <Value>SM</Value>
    </Field>
    </Record>
    <Record>
    <Record>
    <RecordNumber>2</RecordNumber>
    <Status>UnProcessed</Status>
    <Field>
    <Fieldname>ChangeType</Fieldname>
    <Value>SN</Value>
    </Field>
    </Record>
    <Record>
    </ExtractInfo>
    </Extract>

    Any help would be graetly appreciated

    Thanks
     
    , Jan 5, 2007
    #1
    1. Advertising

  2. wrote:

    > I am new to XPATH and am having a hard time selecting some nodes.
    > I want to select all the record nodes where Status = 'Unprocessed' or
    > 'Queued' (that part I can get) but additionally I only want the ones
    > where the Field/Fieldname ='ChangeType' and Field/Value = 'SN'
    > I have //ExtractInfo/Record[Status='UnProcessed' or
    > Status='Queued']/Field[Fieldname='ChangeType' and Value='SN'] but that
    > gets the field nodes, I need the record nodes.


    //ExtractInfo/Record[
    Status='UnProcessed' or Status='Queued' and
    Field[Fieldname='ChangeType' and Value='SN']]



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 5, 2007
    #2
    1. Advertising

  3. * wrote in comp.text.xml:
    >I am new to XPATH and am having a hard time selecting some nodes.
    >I want to select all the record nodes where Status = 'Unprocessed' or
    >'Queued' (that part I can get) but additionally I only want the ones
    >where the Field/Fieldname ='ChangeType' and Field/Value = 'SN'


    You have to formulate these extra conditions as predicates like so:

    //Record[ (Status = 'UnProcessed' or Status = 'Queued') and
    Field[Fieldname = 'ChangeType' and Value = 'SN'] ]
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Jan 5, 2007
    #3
  4. Guest

    Thanks,
    I was dancing all around it. the nested [] is what was tripping me up.

    Martin Honnen wrote:
    > wrote:
    >
    > > I am new to XPATH and am having a hard time selecting some nodes.
    > > I want to select all the record nodes where Status = 'Unprocessed' or
    > > 'Queued' (that part I can get) but additionally I only want the ones
    > > where the Field/Fieldname ='ChangeType' and Field/Value = 'SN'
    > > I have //ExtractInfo/Record[Status='UnProcessed' or
    > > Status='Queued']/Field[Fieldname='ChangeType' and Value='SN'] but that
    > > gets the field nodes, I need the record nodes.

    >
    > //ExtractInfo/Record[
    > Status='UnProcessed' or Status='Queued' and
    > Field[Fieldname='ChangeType' and Value='SN']]
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    , Jan 5, 2007
    #4
    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. asd
    Replies:
    3
    Views:
    458
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    544
    gavnosis
    Aug 2, 2003
  3. Replies:
    0
    Views:
    522
  4. Replies:
    2
    Views:
    4,301
  5. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    831
    David Gordon
    May 18, 2005
Loading...

Share This Page