Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath expression to "select all"?

Reply
Thread Tools

XPath expression to "select all"?

 
 
JS
Guest
Posts: n/a
 
      05-04-2009
I have this XML file:

<root id="root" >
<head>
<section secid="section">
<subsection>
<item order="0">
<data id="D1" value="red"/>
<data id="D2" value="blue"/>
</item>
<item order="1">
<data id="D1" value="green"/>
<data id="D2" value="yellow"/>
</item>
<item order="2">
<data id="D1" value="black"/>
<data id="D2" value="white"/>
</item>
</subsection>
</section>
</head>
</root>

I would like to create a XPath expression that selects all values where data
id="D1". The result should be:

red
green
black

I have tried something like (assuming that we are standing in root):

/head/section/subsection/item/data[@id="D1"]/@value

but it only returns the first value:

red

How do I get the values from the remaining item elements?


 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-05-2009
JS wrote:
> /head/section/subsection/item/data[@id="D1"]/@value
>
> but it only returns the first value:


Actually, it is returning all the values, but the string value of a set
of results is the string value of the first result.

To get the rest, you need to iterate through the results. How you do
that depends on the tool you're using to execute this XPath.
 
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
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
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