Get a collection of attributes of this element in CSharp

Description

The following code shows how to get a collection of attributes of this element.

Example


using System;/*from w w w . j  av a 2 s  . c om*/
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
        XElement xmlTree = new XElement("Root",
            new XAttribute("Att1", "content1"),
            new XAttribute("Att2", "content2")
        );
        IEnumerable<XAttribute> attList = from at in xmlTree.Attributes() select at;
        foreach (XAttribute att in attList)
            Console.WriteLine(att);
   }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style