Displays all the attributes from an Xml tag : XAttribute « XML LINQ « C# / CSharp Tutorial






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();
    }           
  }
}








31.3.XAttribute
31.3.1.Linq To Xml Constructors
31.3.2.Use Linq to read xml file and query attribute value
31.3.3.Displays all the attributes from an Xml tag