hi...I had to read a xml file in c#...i Had written the following code
but the desired output is not coming..
using System;
using System.Xml;
namespace ReadXMLfromFile
{
class Class1
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader("my.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();
}
}
}
the xml file i need to read is
<?xml version="1.0" encoding="utf-8" ?>
<Workflow>
<User UserName="abc" Sirname="xyz"/>
</Workflow>
the output i am getting is:
<Workflow>
<User>
</Workflow>