Mega Code Archive

 
Categories / C# / XML
 

Get first child and its Node List

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; using System.Xml; public class XML {     public void LoadXML()     {         string filePath = @"..\..\booklist.xml";         XmlDocument xDoc = new XmlDocument();         xDoc.LoadXml(filePath);         XmlElement eBook = xDoc.DocumentElement;         XmlElement eFirstBook = (XmlElement)eBook.FirstChild;         XmlNodeList nlChilds = eFirstBook.ChildNodes;         for (int i = 0; i < nlChilds.Count; i++)         {             XmlElement eChild = (XmlElement)nlChilds[i];             Console.WriteLine(eChild.Name + ":" + eChild.InnerText);         }     } }