Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
XAttribute Class
.NET Framework Class Library
XAttribute Class

Updated: November 2007

Represents an XML attribute.

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

Visual Basic (Declaration)
Public Class XAttribute _
    Inherits XObject
Visual Basic (Usage)
Dim instance As XAttribute
C#
public class XAttribute : XObject
Visual C++
public ref class XAttribute : public XObject
J#
public class XAttribute extends XObject
JScript
public class XAttribute extends XObject

An XML attribute is a name/value pair associated with an XML element.

Each XElement contains a list of the attributes for that element. Attributes must have a qualified name that is unique to the element. Attributes are not derived from XNode; they are not nodes in the XML tree. Instead, they are simply name/value pairs associated with an element.

Attributes are maintained in the XML tree in the order that they were added to the element. When a collection of attributes is returned by Attributes, they are returned in the order that they were added to the element, and are not sorted.

Technically, in XML, namespace declarations are not attributes proper. However, this distinction is not normally made by many XML programmers. Instead, because namespace declarations have exactly the same XML syntax as attributes, most XML programmers think of namespaces as attributes. To simplify the LINQ to XML programming interface, namespaces are represented in the XML tree as attributes. Such namespace attributes impact serialization of an XML tree. When serializing, LINQ to XML attempts to serialize with the namespace prefix specified in namespace attributes. You can use the IsNamespaceDeclaration to determine if an attribute is really a namespace declaration.

The XAttribute class derives from XObject. You can add annotations to attributes, and observe events for them.

Some XAttribute methods can be used from XAML. For more information, see LINQ to XML Dynamic Properties.

System..::.Object
  System.Xml.Linq..::.XObject
    System.Xml.Linq..::.XAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker