tags:

views:

28

answers:

1

Hi , I'm newbie in XML ^_^

<a>
<book>
  <c>
       <e>Val1</e>
  </c>
  <d>val2</d>
</book>
<book>
  <c>
       <e>Val3</e>
  </c>
  <d>val4</d>
</book>

Question is i need to get value inside each book first i use

XmlNodeList xnList = xDoc.SelectNodes("/a/book");

problem is node "c" has child "e" so i cant get its value like i get directly from node "d"

foreach (XmlNode xn in xnList)
            {
                string Name = xn["e"].InnerText;   // Can't get its value
                string Detail = xn["d"].InnerText;
            }

Thanks

+1  A: 

You need to select subnodes below the <book> node:

XmlNodeList xnList = xDoc.SelectNodes("/a/book");

foreach (XmlNode xn in xnList)
{
    XmlNode eNode = xn.SelectSingleNode("c/e");

    if(eNode != null)
    {
         string Name = eNode.InnerText;
    }
}
marc_s