C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 21 October 2014

Reading a XML

XML
<?xml version="1.0" encoding="utf-8" ?>
<country name="India">
  <state name="KARNATAKA"></state>
  <state name="UP"></state>

</country>

-------------------------------------------------------

using System;
using System.Xml;

namespace XML
{
    class Program
    {
        static void Main(string[] args)
        {


            XmlReader reader = XmlReader.Create(@"c:\users\anayak\documents\visual studio 2012\Projects\XML\XML\XMLFile1.xml");

                while (reader.Read())
                {

                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "state"))
                    {
                        if (reader.HasAttributes)
                        {
                            Console.WriteLine(reader.GetAttribute("name"));

                        }

                    }
                }
            
            Console.ReadLine();

        }
    }
}

OUTPUT