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();
navigator.MoveToRoot();
navigator.MoveToFirstChild();
while (navigator.MoveToNext())
{
navigator.MoveToFirstChild();
do
{
string id = navigator.GetAttribute("employeeid", "");
if (id == "1")
{
XmlReader reader=navigator.ReadSubtree();
DisplayDetails(reader);
}
}
while (navigator.MoveToNext());
}
}
private static void DisplayDetails(XmlReader reader)
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "firstname":
Console.WriteLine(reader.ReadString());
break;
case "lastname":
Console.WriteLine(reader.ReadString());
break;
case "homephone":
Console.WriteLine(reader.ReadString());
break;
case "notes":
Console.WriteLine(reader.ReadString());
break;
}
}
}
reader.Close();
}
}
|