XAttribute Class (System.Xml.Linq)

Switch View :
ScriptFree
.NET Framework Class Library
XAttribute Class

Represents an XML attribute.

Inheritance Hierarchy

System.Object
  System.Xml.Linq.XObject
    System.Xml.Linq.XAttribute

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

Visual Basic
Public Class XAttribute _
	Inherits XObject
C#
public class XAttribute : XObject
Visual C++
public ref class XAttribute : public XObject
F#
type XAttribute =  
    class
        inherit XObject
    end

The XAttribute type exposes the following members.

Constructors

  Name Description
Public method Supported by the XNA Framework XAttribute(XAttribute) Initializes a new instance of the XAttribute class from another XAttribute object.
Public method Supported by the XNA Framework XAttribute(XName, Object) Initializes a new instance of the XAttribute class from the specified name and value.
Top
Properties

  Name Description
Public property Supported by the XNA Framework BaseUri Gets the base URI for this XObject. (Inherited from XObject.)
Public property Supported by the XNA Framework Document Gets the XDocument for this XObject. (Inherited from XObject.)
Public property Static member Supported by the XNA Framework EmptySequence Gets an empty collection of attributes.
Public property Supported by the XNA Framework IsNamespaceDeclaration Determines if this attribute is a namespace declaration.
Public property Supported by the XNA Framework Name Gets the expanded name of this attribute.
Public property Supported by the XNA Framework NextAttribute Gets the next attribute of the parent element.
Public property Supported by the XNA Framework NodeType Gets the node type for this node. (Overrides XObject.NodeType.)
Public property Supported by the XNA Framework Parent Gets the parent XElement of this XObject. (Inherited from XObject.)
Public property Supported by the XNA Framework PreviousAttribute Gets the previous attribute of the parent element.
Public property Supported by the XNA Framework Value Gets or sets the value of this attribute.
Top
Methods

  Name Description
Public method Supported by the XNA Framework AddAnnotation Adds an object to the annotation list of this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework Annotation(Type) Gets the first annotation object of the specified type from this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework Annotation<T>() Get the first annotation object of the specified type from this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework Annotations(Type) Gets a collection of annotations of the specified type for this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework Annotations<T>() Gets a collection of annotations of the specified type for this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by the XNA Framework Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by the XNA Framework GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by the XNA Framework MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework Remove Removes this attribute from its parent element.
Public method Supported by the XNA Framework RemoveAnnotations(Type) Removes the annotations of the specified type from this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework RemoveAnnotations<T>() Removes the annotations of the specified type from this XObject. (Inherited from XObject.)
Public method Supported by the XNA Framework SetValue Sets the value of this attribute.
Public method Supported by the XNA Framework ToString Converts the current XAttribute object to a string representation. (Overrides Object.ToString().)
Top
Events

  Name Description
Public event Supported by the XNA Framework Changed Raised when this XObject or any of its descendants have changed. (Inherited from XObject.)
Public event Supported by the XNA Framework Changing Raised when this XObject or any of its descendants are about to change. (Inherited from XObject.)
Top
Operators

  Name Description
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to DateTime) Cast the value of this XAttribute to a DateTime.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<DateTime>) Cast the value of this XAttribute to a Nullable<T> of DateTime.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Decimal>) Cast the value of this XAttribute to a Nullable<T> of Decimal.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Double>) Cast the value of this XAttribute to a Nullable<T> of Double.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Decimal) Cast the value of this XAttribute to a Decimal.
Public operator Static member Explicit(XAttribute to DateTimeOffset) Cast the value of this XAttribute to a DateTimeOffset.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Guid) Cast the value of this XAttribute to a Guid.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Guid>) Cast the value of this XAttribute to a Nullable<T> of Guid.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<TimeSpan>) Cast the value of this XAttribute to a Nullable<T> of TimeSpan.
Public operator Static member Explicit(XAttribute to Nullable<DateTimeOffset>) Cast the value of this XAttribute to a Nullable<T> of DateTimeOffset.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to TimeSpan) Cast the value of this XAttribute to a TimeSpan.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Double) Cast the value of this XAttribute to a Double.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Int32) Cast the value of this XAttribute to an Int32.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Int32>) Cast the value of this XAttribute to a Nullable<T> of Int32.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to UInt32) Cast the value of this XAttribute to a UInt32.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to String) Cast the value of this XAttribute to a String.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Boolean) Cast the value of this XAttribute to a Boolean.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Boolean>) Cast the value of this XAttribute to a Nullable<T> of Boolean.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<UInt32>) Cast the value of this XAttribute to a Nullable<T> of UInt32.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<UInt64>) Cast the value of this XAttribute to a Nullable<T> of UInt64.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Single) Cast the value of this XAttribute to a Single.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Single>) Cast the value of this XAttribute to a Nullable<T> of Single.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Int64) Cast the value of this XAttribute to an Int64.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to Nullable<Int64>) Cast the value of this XAttribute to a Nullable<T> of Int64.
Public operator Static member Supported by the XNA Framework Explicit(XAttribute to UInt64) Cast the value of this XAttribute to a UInt64.
Top
Extension Methods

  Name Description
Public Extension Method GetSchemaInfo Gets the post-schema-validation infoset (PSVI) of a validated attribute. (Defined by Extensions.)
Public Extension Method Validate(XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Overloaded. This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet. (Defined by Extensions.)
Public Extension Method Validate(XmlSchemaObject, XmlSchemaSet, ValidationEventHandler, Boolean) Overloaded. Validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet, optionally populating the XML tree with the post-schema-validation infoset (PSVI). (Defined by Extensions.)
Top
Explicit Interface Implementations

  Name Description
Explicit interface implemetation Private method Supported by the XNA Framework IXmlLineInfo.HasLineInfo Gets a value indicating whether or not this XObject has line information. (Inherited from XObject.)
Explicit interface implemetation Private property Supported by the XNA Framework IXmlLineInfo.LineNumber Gets the line number that the underlying XmlReader reported for this XObject. (Inherited from XObject.)
Explicit interface implemetation Private property Supported by the XNA Framework IXmlLineInfo.LinePosition Gets the line position that the underlying XmlReader reported for this XObject. (Inherited from XObject.)
Top
Remarks

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.

Version Information

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources