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.

StringBuilder output = new StringBuilder();
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
    new XAttribute(aw + "Att", "content"),
    new XAttribute("Att2", "different content")

foreach (XAttribute att in root.Attributes())
    output.Append(att.Name + "=" + att.Value + Environment.NewLine);
output.Append("" + Environment.NewLine);

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())
    output.Append(att.Name + "=" + att.Value + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions