In this blog 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.
<?xml version="1.0" encoding="utf-8" ?>
<Address>333 Indiana Street</Address>
<Address>222 West Region</Address>
Add the following namespace in your application
Now we can open the XPathDocument object as follows
XPathDocument Doc = new XPathDocument("emp.xml");
XPathNavigator navigator = Doc.CreateNavigator();
Using this navigator object, we can traverse through the document. We can provide XPath expressions as shown below
XPathNodeIterator iterator = navigator.Select("/Employees");
Try changing the XPath expression as demonstrated below.
iterator = navigator.Select("/Employees/Employee");
iterator = navigator.Select("/Employees/Employee[Age>22]");
iterator = navigator.Select("/Employees/Employee[Age>22]/Name");Hope this helps :-)