The problem I have is I would like to "skip" the first country node and only use the second one. However, they both have the name "country", so if I use XPATH like '/nsw:foods/nsw:country' then it just selects the whole lot, all of the country nodes...so
I really need a way of saying "miss out the first one"...I'm new to xpath so have tried various things with no luck. Anybody know how I could do this?
Matt3.5
Member
333 Points
92 Posts
How to select one of two XML nodes with same name?
Oct 30, 2008 10:08 PM|LINK
Hi,
I have some XML like:
<country>
<city></city>
</country>
<country>
<city></city>
</country>
The problem I have is I would like to "skip" the first country node and only use the second one. However, they both have the name "country", so if I use XPATH like '/nsw:foods/nsw:country' then it just selects the whole lot, all of the country nodes...so I really need a way of saying "miss out the first one"...I'm new to xpath so have tried various things with no luck. Anybody know how I could do this?
Thanks
Bonekrusher
Contributor
4027 Points
922 Posts
Re: How to select one of two XML nodes with same name?
Oct 30, 2008 11:29 PM|LINK
You can use predicates:
/nsw:foods/nsw:country[2]
ksridharbabu...
Star
9239 Points
1356 Posts
Re: How to select one of two XML nodes with same name?
Oct 31, 2008 05:53 AM|LINK
Hi,
You can achieve the same using xPath with position function as shown below:
country[position() > 1]
Or you can also achieve as specified in the previous thread.
Visit My Blog
-------------------------------------------------
If this post was useful to you, please mark it as answer. Thank you!