Read Attributes and Elements of XML Documents

    public void ReadAEOfXml()
    {

        XmlTextReader xtr = new XmlTextReader("D:/mapping1.xml");
        while(xtr.Read())
        {
            XmlNodeType xmlnotetype = xtr.NodeType;
            switch (xmlnotetype)
            { 
                case XmlNodeType.Element :
                    Response.Write(string.Format("Element name= {0}",xtr.Name) + "</BR>");
                    if (xtr.HasAttributes)
                    {
                        for (int i = 0; i < xtr.AttributeCount; i++)
                        {
                            xtr.MoveToAttribute(i);
                            Response.Write(string.Format("Element is {0} and Attributes is: {1}", xtr.Name, xtr.Value) + "</BR>");
                        }
                    
                    }
                 break;
                case XmlNodeType.Text:
                 Response.Write(string.Format("value is {0}", xtr.Value) + "</BR>");
                 break;
           
            }
 
        }
   
    }
Advertisements
This entry was posted in Asp.Net and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s