XAttribute Class

 

Represents an XML attribute.

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

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

public class XAttribute : XObject

NameDescription
System_CAPS_pubmethodXAttribute(XAttribute)

Initializes a new instance of the XAttribute class from another XAttribute object.

System_CAPS_pubmethodXAttribute(XName, Object)

Initializes a new instance of the XAttribute class from the specified name and value.

NameDescription
System_CAPS_pubpropertyBaseUri

Gets the base URI for this XObject.(Inherited from XObject.)

System_CAPS_pubpropertyDocument

Gets the XDocument for this XObject.(Inherited from XObject.)

System_CAPS_pubpropertySystem_CAPS_staticEmptySequence

Gets an empty collection of attributes.

System_CAPS_pubpropertyIsNamespaceDeclaration

Determines if this attribute is a namespace declaration.

System_CAPS_pubpropertyName

Gets the expanded name of this attribute.

System_CAPS_pubpropertyNextAttribute

Gets the next attribute of the parent element.

System_CAPS_pubpropertyNodeType

Gets the node type for this node.(Overrides XObject.NodeType.)

System_CAPS_pubpropertyParent

Gets the parent XElement of this XObject.(Inherited from XObject.)

System_CAPS_pubpropertyPreviousAttribute

Gets the previous attribute of the parent element.

System_CAPS_pubpropertyValue

Gets or sets the value of this attribute.

NameDescription
System_CAPS_pubmethodAddAnnotation(Object)

Adds an object to the annotation list of this XObject.(Inherited from XObject.)

System_CAPS_pubmethodAnnotation(Type)

Gets the first annotation object of the specified type from this XObject.(Inherited from XObject.)

System_CAPS_pubmethodAnnotation<T>()

Get the first annotation object of the specified type from this XObject. (Inherited from XObject.)

System_CAPS_pubmethodAnnotations(Type)

Gets a collection of annotations of the specified type for this XObject.(Inherited from XObject.)

System_CAPS_pubmethodAnnotations<T>()

Gets a collection of annotations of the specified type for this XObject.(Inherited from XObject.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRemove()

Removes this attribute from its parent element.

System_CAPS_pubmethodRemoveAnnotations(Type)

Removes the annotations of the specified type from this XObject.(Inherited from XObject.)

System_CAPS_pubmethodRemoveAnnotations<T>()

Removes the annotations of the specified type from this XObject.(Inherited from XObject.)

System_CAPS_pubmethodSetValue(Object)

Sets the value of this attribute.

System_CAPS_pubmethodToString()

Converts the current XAttribute object to a string representation.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubeventChanged

Raised when this XObject or any of its descendants have changed.(Inherited from XObject.)

System_CAPS_pubeventChanging

Raised when this XObject or any of its descendants are about to change.(Inherited from XObject.)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Boolean)

Cast the value of this XAttribute to a Boolean.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to DateTime)

Cast the value of this XAttribute to a DateTime.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to DateTimeOffset)

Cast the value of this XAttribute to a DateTimeOffset.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Decimal)

Cast the value of this XAttribute to a Decimal.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Double)

Cast the value of this XAttribute to a Double.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Guid)

Cast the value of this XAttribute to a Guid.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Int32)

Cast the value of this XAttribute to an Int32.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Int64)

Cast the value of this XAttribute to an Int64.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Boolean>)

Cast the value of this XAttribute to a Nullable<T> of Boolean.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<DateTime>)

Cast the value of this XAttribute to a Nullable<T> of DateTime.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<DateTimeOffset>)

Cast the value of this XAttribute to a Nullable<T> of DateTimeOffset.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Decimal>)

Cast the value of this XAttribute to a Nullable<T> of Decimal.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Double>)

Cast the value of this XAttribute to a Nullable<T> of Double.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Guid>)

Cast the value of this XAttribute to a Nullable<T> of Guid.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Int32>)

Cast the value of this XAttribute to a Nullable<T> of Int32.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Int64>)

Cast the value of this XAttribute to a Nullable<T> of Int64.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<Single>)

Cast the value of this XAttribute to a Nullable<T> of Single.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<TimeSpan>)

Cast the value of this XAttribute to a Nullable<T> of TimeSpan.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<UInt32>)

Cast the value of this XAttribute to a Nullable<T> of UInt32.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Nullable<UInt64>)

Cast the value of this XAttribute to a Nullable<T> of UInt64.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to Single)

Cast the value of this XAttribute to a Single.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to String)

Cast the value of this XAttribute to a String.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to TimeSpan)

Cast the value of this XAttribute to a TimeSpan.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to UInt32)

Cast the value of this XAttribute to a UInt32.

System_CAPS_puboperatorSystem_CAPS_staticExplicit(XAttribute to UInt64)

Cast the value of this XAttribute to a UInt64.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIXmlLineInfo.HasLineInfo()

Gets a value indicating whether or not this XObject has line information.(Inherited from XObject.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIXmlLineInfo.LineNumber

Gets the line number that the underlying XmlReader reported for this XObject.(Inherited from XObject.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIXmlLineInfo.LinePosition

Gets the line position that the underlying XmlReader reported for this XObject.(Inherited from XObject.)

NameDescription
System_CAPS_pubmethodGetSchemaInfo()

Overloaded. Gets the post-schema-validation infoset (PSVI) of a validated attribute.(Defined by Extensions.)

System_CAPS_pubmethodValidate(XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)

Overloaded. This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.(Defined by Extensions.)

System_CAPS_pubmethodValidate(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.)

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

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

Return to top
Show: