tags:

views:

25

answers:

2

I'm trying to select the second child node off the root and all it's children from XML that looks similar to this:

<root>
   <SET>
      <element>
      <element>
   </SET>
   <SET>
      <element>
      <element>
   </SET>
<root>

I'm after all the tags in the second node, any help would be greatly appreciated!

I'm using C#. I tried the XPath /SET[1] however that didn't see to help!

Many thanks!

C

+1  A: 
x/y[1] : 
     The first <y> child of each <x>. This is equivalent to the expression in the next row.

x/y[position() = 1] :The first <y> child of each <x>.

Try this :

string xpath = "/root/set[2]";
XmlNode locationNode = doc.SelectSingleNode(xpath); 

or

string xpath = "/root/set[position() = 2]";
XmlNode locationNode = doc.SelectSingleNode(xpath); 
Pranay Rana
This worked perfectly. Thank you!
Chris M
you can get more info about xpath over here : http://msdn.microsoft.com/en-us/library/ms256086.aspx
Pranay Rana
A: 

XPath is not zero-index based, it's one-indexed.

You want: root/set[2]

annakata
Hi, old friend, you forgot the starting slash. :)
Dimitre Novatchev