Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath and nodes?

Reply
Thread Tools

XPath and nodes?

 
 
JS
Guest
Posts: n/a
 
      04-23-2009
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?


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-24-2009
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57