This documentation is archived and is not being maintained.

XAttribute.Name Property

Gets the expanded name of this attribute.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

public XName Name { get; }

Property Value

Type: System.Xml.Linq.XName
An XName containing the name of this attribute.

The expanded name returned by this property is in the form of {namespace}localname.

The following example creates an element with three attributes. It then uses this property to print out the name of each attribute. The example also shows creation of a new attribute using the name of an existing attribute.

XNamespace aw = "";
XElement root = new XElement(aw + "Root",
    new XAttribute(XNamespace.Xmlns + "aw", ""),
    new XAttribute(aw + "Att", "content"),
    new XAttribute("Att2", "different content")

foreach (XAttribute att in root.Attributes())
    Console.WriteLine("{0}={1}", att.Name, att.Value);

XElement newRoot = new XElement(aw + "Root",
    from att in root.Attributes("Att2")
    select new XAttribute(att.Name, "new content"));

foreach (XAttribute att in newRoot.Attributes())
    Console.WriteLine("{0}={1}", att.Name, att.Value);

This example produces the following output:

Att2=different content

Att2=new content

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0