StatCounter

View My Stats

Friday, February 6, 2009

Simple XML Text Reader Example in C# Console Appln

Simple XML Text Reader Example in C# Console Appln


using System;
using System.Xml;

namespace ReadXMLfromFile
{
///


/// Summary description for Class1.
///
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("books.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
}

No comments: