Mega Code Archive

 
Categories / C# Tutorial / XML LINQ
 

Displays all the attributes from an Xml tag

using System; using System.IO; using System.Xml; public class Sample {   public static void Main(){     XmlDocument doc = new XmlDocument();     doc.LoadXml("<book genre='novel' ISBN='11111111111'>" +                 "<title>AAA</title>" +                 "</book>");           //Create an attribute collection.      XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;     Console.WriteLine("Display all the attributes in the collection...\r\n");     for (int i=0; i < attrColl.Count; i++)     {       Console.Write("{0} = ", attrColl[i].Name);       Console.Write("{0}", attrColl[i].Value);       Console.WriteLine();     }              } }