Get Node information by using XPathNavigator
using System;
using System.Xml.XPath;
using System.Xml;
class MainClass
{
static void Main(string[] args)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\books.xml");
XPathNavigator nav = xmlDoc.CreateNavigator();
nav.MoveToRoot();
string name = nav.Name;
Console.WriteLine("Root node info: ");
Console.WriteLine("Base URI" + nav.BaseURI.ToString());
Console.WriteLine("Name: " +nav.Name.ToString());
Console.WriteLine("Node Type: "+ nav.NodeType.ToString());
Console.WriteLine("Node Value: "+nav.Value.ToString());
if (nav.HasChildren)
{
nav.MoveToFirstChild();
GetNodeInfo(nav);
}
}
private static void GetNodeInfo( XPathNavigator nav1)
{
Console.WriteLine("Name: " +nav1.Name.ToString());
Console.WriteLine("Node Type: "+ nav1.NodeType.ToString());
Console.WriteLine("Node Value: "+nav1.Value.ToString());
if (nav1.HasChildren)
{
nav1.MoveToFirstChild();
while( nav1.MoveToNext() )
{
GetNodeInfo(nav1);
nav1.MoveToParent();
}
} else {
nav1.MoveToNext();
GetNodeInfo(nav1);
}
}
}
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
|