Introduction In this article I am going to give an overview of how we can easily parse and get the data from an XML file. For demonstrating, I have created a sample XML file listed below. {codecitation class="brush: csharp; gutter: true;" width="700px"}
Amal 26 333 Indiana Street Munna 20 222 West Region
{/codecitation}
Add the following namespace in your application
using System.Xml.XPath;
Now we can open the XPathDocument object as follows
XPathDocument Doc = new XPathDocument("emp.xml");
Once this is done, we need a XPathNavigator
XPathNavigator navigator = Doc.CreateNavigator();
Using this navigator object, we can traverse through the document. We can provide XPath expressions as shown below
{codecitation class="brush: csharp; gutter: true;" width="700px"}
XPathNodeIterator iterator = navigator.Select("/Employees"); while (iterator.MoveNext()) { Console.WriteLine(iterator.Current.Name); Console.WriteLine(iterator.Current.Value); }
{/codecitation} 
Try changing the XPath expression as demonstrated below.
{codecitation class="brush: csharp; gutter: true;" width="700px"}
iterator = navigator.Select("/Employees/Employee");
iterator = navigator.Select("/Employees/Employee[Age>22]");
iterator = navigator.Select("/Employees/Employee[Age>22]/Name");
{/codecitation} I hope this is help to all. Thank you Amal |