Parsing XML with the XmlDocument
XML Parser in C# and VB.Net

XmlDocument Class represents an XML document. XmlDocument reads the entire XML content into memory and then allow you to navigate back and forward in it or even query the XML document using the XPath technology.
Using XPath with the XmlDocument class

XmlNodeList Class Represents an ordered collection of nodes. In order to find nodes in an XML file you can use XPath expressions. Method XmlNode.SelectNodes returns a list of nodes selected by the XPath string.
doc.DocumentElement.SelectNodes("/Store/Product");Reading XML with the XmlDocument class
XML File content
1 Product 1 1000 2 Product 2 2000 3 Product 3 3000 4 Product 4 4000
Click here to download Product.xml
Parse XML with XmlDocument
The following program describes how to use the XmlDocument class to parse an XML document in C#.
C# XmlDocument exampleusing System; using System.Data; using System.Xml; using System.IO; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load("d:\\product.xml"); XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Store/Product"); string product_id = "", product_name = "", product_price=""; foreach (XmlNode node in nodes) { product_id = node.SelectSingleNode("Product_id").InnerText; product_name = node.SelectSingleNode("Product_name").InnerText; product_price = node.SelectSingleNode("Product_price").InnerText; MessageBox.Show(product_id + " " + product_name + " " + product_price); } } } }VB.Net XmlDocument example

This following program describes how to use the XmlDocument class to parse an XML document in VB.Net.
Imports System.Xml Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim doc As New XmlDocument() doc.Load("d:\product.xml") Dim nodes As XmlNodeList = doc.DocumentElement.SelectNodes("/Store/Product") Dim product_id As String = "", product_name As String = "", product_price As String = "" For Each node As XmlNode In nodes product_id = node.SelectSingleNode("Product_id").InnerText product_name = node.SelectSingleNode("Product_name").InnerText product_price = node.SelectSingleNode("Product_price").InnerText MessageBox.Show(product_id & " " & product_name & " " & product_price) Next End Sub End Class
NEXT.....File.Exists Method