Read XML File Using C#
using System;
using System.Xml;
class ClassXML
{
static void Main(string[] args)
{
XmlTextReader XMLreader = new XmlTextReader ("XMLFilePath.xml");
while (XMLreader.Read())
{
switch (XMLreader.NodeType)
{
case XmlNodeType.Element: // The Element node.
Console.Write("<" + XMLreader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: // Display the Each element text.
Console.WriteLine (XMLreader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + XMLreader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
using System.Xml;
class ClassXML
{
static void Main(string[] args)
{
XmlTextReader XMLreader = new XmlTextReader ("XMLFilePath.xml");
while (XMLreader.Read())
{
switch (XMLreader.NodeType)
{
case XmlNodeType.Element: // The Element node.
Console.Write("<" + XMLreader.Name);
Console.WriteLine(">");
break;
case XmlNodeType.Text: // Display the Each element text.
Console.WriteLine (XMLreader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
Console.Write("</" + XMLreader.Name);
Console.WriteLine(">");
break;
}
}
Console.ReadLine();
}
}
0 comments: