Mega Code Archive

 
Categories / C# Tutorial / XML
 

Using XPathNodeIterator

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using System.Xml.XPath;     public class MainClass     {         public static void Main()         {             XPathDocument doc = new XPathDocument(Application.StartupPath + @"\employees.xml");             XPathNavigator navigator = doc.CreateNavigator();             XPathNodeIterator iterator=navigator.Select("your input");             try             {                 Console.WriteLine("The expressions returned " + iterator.Count + " nodes");                 if (iterator.Count > 0)                 {                     while (iterator.MoveNext())                     {                         Console.WriteLine(iterator.Current.OuterXml);                     }                 }             }             catch (Exception ex)             {                 MessageBox.Show(ex.Message);             }         }     }