Wednesday, July 1, 2009

How TO READ XML IN C#

This is my Second post regarding XML. In first post i told you that how to create a xml file in C#. Now we will learn that how can we read a xml file in c#.

To read an XML file in c# you need to add a namespace.

using System.XML;

Now write the below code to read xml file.

XmlTextReader reader = new XmlTextReader(filename);
reader.Read();
while (reader.Read())
{
if(reader.Value.Trim()!="")
Console.WriteLine("Attribute Count={0}, Attribute={1}, Value={2}", reader.AttributeCount, reader.GetAttribute("name"),reader.Value);
}



I used this code to get my result which I want. You can modify the code to get yours one.

Enjoy..........

No comments:

Docker Tutorial

 I have listed all the necessary commands of Docker below. In case if any is missing or if any improvement required, please share in comment...