XPath and nodes?

Discussion in 'XML' started by JS, Apr 24, 2009.

  1. JS

    JS Guest

    I have the below xml file:

    <root>
    <row order="0">
    <data id="LT1" value="Width"/>
    <data id="item" value="40 cm"/>
    </row>
    <row order="1">
    <data id="LT1" value="Height"/>
    <data id="item" value="20 cm"/>
    </row>
    </root>

    I would like to define a XPath variable where id=LT1. I have tried:

    Name: LT1
    XPath: @id="LT1"

    But when I use the "new" variable LT1 it returns nothing. How do I make a
    new variable which only extracts data where id=LT1?
     
    JS, Apr 24, 2009
    #1
    1. Advertising

  2. JS wrote:
    > I have the below xml file:
    >
    > <root>
    > <row order="0">
    > <data id="LT1" value="Width"/>
    > <data id="item" value="40 cm"/>
    > </row>
    > <row order="1">
    > <data id="LT1" value="Height"/>
    > <data id="item" value="20 cm"/>
    > </row>
    > </root>
    >
    > I would like to define a XPath variable where id=LT1. I have tried:
    >
    > Name: LT1
    > XPath: @id="LT1"
    >
    > But when I use the "new" variable LT1 it returns nothing. How do I make
    > a new variable which only extracts data where id=LT1?


    It is not clear to me what exactly you want to achieve.
    The XPath
    /root/row[data[@id = 'LT1']]
    would select all 'row' element children of the 'root' element which have
    a 'data' child with the 'id' attribute value being 'LT1'.
    If you do not want to select the 'row' elements but rather the 'data'
    elements then use
    /root/row/data[@id = 'LT1']

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Apr 24, 2009
    #2
    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:
    440
    Arnaud Berger
    May 23, 2005
  2. gavnosis
    Replies:
    0
    Views:
    525
    gavnosis
    Aug 2, 2003
  3. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    409
    Patrick TJ McPhee
    Jun 17, 2004
  4. Johnny Ooi

    Looking A Nodes From Within Nodes

    Johnny Ooi, Nov 13, 2004, in forum: XML
    Replies:
    10
    Views:
    657
    Johnny Ooi
    Nov 14, 2004
  5. Replies:
    5
    Views:
    488
    bouton
    Sep 22, 2005
Loading...

Share This Page