Reputation: 504
I have an xml file with a structure like this:
<xml>
<tag>
<name>paul</name>
<value>1</value>
</tag>
<tag>
<name>mary</name>
<value>2</value>
</tag>
<tag>
<name>john</name>
<value>3</value>
</tag>
<xml>
My question is, how could i reach each tags value tag using xpath?
Upvotes: 0
Views: 168
Reputation: 89325
To get all <value>
within <tag>
:
/xml/tag/value
If you meant to get <value>
by value of <name>
as stated in your comment, you can do something like this :
/xml/tag[name='paul']/value
Above example will return <value>1</value>
Upvotes: 2
Reputation: 7173
try
/xml/tag[name ='paul']/value
/xml/tag[name ='mary']/value
/xml/tag[name ='john']/value
Upvotes: 1
Reputation: 6796
If you want to get a list of the whole value elements:
//tag/value
but if you don't need the wrapping value element, just the values within the tags:
//tag/value/text()
Upvotes: 0
Reputation: 9274
Use predicates to uniquely access a value
First element: /xml/tag[1]/name
Last element: /xml/tag[last()]/name
etc.
Upvotes: 0