XAttribute XAttribute XAttribute XAttribute Class

Definition

Represents an XML attribute.

public ref class XAttribute : System::Xml::Linq::XObject
public class XAttribute : System.Xml.Linq.XObject
type XAttribute = class
    inherit XObject
Public Class XAttribute
Inherits XObject
Inheritance
XAttributeXAttributeXAttributeXAttribute

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.

Constructors

XAttribute(XAttribute) XAttribute(XAttribute) XAttribute(XAttribute) XAttribute(XAttribute)

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

XAttribute(XName, Object) XAttribute(XName, Object) XAttribute(XName, Object) XAttribute(XName, Object)

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

Properties

BaseUri BaseUri BaseUri BaseUri

Gets the base URI for this XObject.

(Inherited from XObject)
Document Document Document Document

Gets the XDocument for this XObject.

(Inherited from XObject)
EmptySequence EmptySequence EmptySequence EmptySequence

Gets an empty collection of attributes.

IsNamespaceDeclaration IsNamespaceDeclaration IsNamespaceDeclaration IsNamespaceDeclaration

Determines if this attribute is a namespace declaration.

IXmlLineInfo.LineNumber IXmlLineInfo.LineNumber IXmlLineInfo.LineNumber IXmlLineInfo.LineNumber

Gets the line number that the underlying XmlReader reported for this XObject.

(Inherited from XObject)
IXmlLineInfo.LinePosition IXmlLineInfo.LinePosition IXmlLineInfo.LinePosition IXmlLineInfo.LinePosition

Gets the line position that the underlying XmlReader reported for this XObject.

(Inherited from XObject)
Name Name Name Name

Gets the expanded name of this attribute.

NextAttribute NextAttribute NextAttribute NextAttribute

Gets the next attribute of the parent element.

NodeType NodeType NodeType NodeType

Gets the node type for this node.

Parent Parent Parent Parent

Gets the parent XElement of this XObject.

(Inherited from XObject)
PreviousAttribute PreviousAttribute PreviousAttribute PreviousAttribute

Gets the previous attribute of the parent element.

Value Value Value Value

Gets or sets the value of this attribute.

Methods

AddAnnotation(Object) AddAnnotation(Object) AddAnnotation(Object) AddAnnotation(Object)

Adds an object to the annotation list of this XObject.

(Inherited from XObject)
Annotation(Type) Annotation(Type) Annotation(Type) Annotation(Type)

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

(Inherited from XObject)
Annotation<T>() Annotation<T>() Annotation<T>() Annotation<T>()

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

(Inherited from XObject)
Annotations(Type) Annotations(Type) Annotations(Type) Annotations(Type)

Gets a collection of annotations of the specified type for this XObject.

(Inherited from XObject)
Annotations<T>() Annotations<T>() Annotations<T>() Annotations<T>()

Gets a collection of annotations of the specified type for this XObject.

(Inherited from XObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove() Remove() Remove() Remove()

Removes this attribute from its parent element.

RemoveAnnotations(Type) RemoveAnnotations(Type) RemoveAnnotations(Type) RemoveAnnotations(Type)

Removes the annotations of the specified type from this XObject.

(Inherited from XObject)
RemoveAnnotations<T>() RemoveAnnotations<T>() RemoveAnnotations<T>() RemoveAnnotations<T>()

Removes the annotations of the specified type from this XObject.

(Inherited from XObject)
SetValue(Object) SetValue(Object) SetValue(Object) SetValue(Object)

Sets the value of this attribute.

ToString() ToString() ToString() ToString()

Converts the current XAttribute object to a string representation.

Operators

Explicit(XAttribute to Boolean) Explicit(XAttribute to Boolean) Explicit(XAttribute to Boolean) Explicit(XAttribute to Boolean)

Cast the value of this XAttribute to a Boolean.

Explicit(XAttribute to DateTime) Explicit(XAttribute to DateTime) Explicit(XAttribute to DateTime) Explicit(XAttribute to DateTime)

Cast the value of this XAttribute to a DateTime.

Explicit(XAttribute to DateTimeOffset) Explicit(XAttribute to DateTimeOffset) Explicit(XAttribute to DateTimeOffset) Explicit(XAttribute to DateTimeOffset)

Cast the value of this XAttribute to a DateTimeOffset.

Explicit(XAttribute to Decimal) Explicit(XAttribute to Decimal) Explicit(XAttribute to Decimal) Explicit(XAttribute to Decimal)

Cast the value of this XAttribute to a Decimal.

Explicit(XAttribute to Double) Explicit(XAttribute to Double) Explicit(XAttribute to Double) Explicit(XAttribute to Double)

Cast the value of this XAttribute to a Double.

Explicit(XAttribute to Guid) Explicit(XAttribute to Guid) Explicit(XAttribute to Guid) Explicit(XAttribute to Guid)

Cast the value of this XAttribute to a Guid.

Explicit(XAttribute to Int32) Explicit(XAttribute to Int32) Explicit(XAttribute to Int32) Explicit(XAttribute to Int32)

Cast the value of this XAttribute to an Int32.

Explicit(XAttribute to Int64) Explicit(XAttribute to Int64) Explicit(XAttribute to Int64) Explicit(XAttribute to Int64)

Cast the value of this XAttribute to an Int64.

Explicit(XAttribute to Nullable<Boolean>) Explicit(XAttribute to Nullable<Boolean>) Explicit(XAttribute to Nullable<Boolean>) Explicit(XAttribute to Nullable<Boolean>)

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

Explicit(XAttribute to Nullable<DateTime>) Explicit(XAttribute to Nullable<DateTime>) Explicit(XAttribute to Nullable<DateTime>) Explicit(XAttribute to Nullable<DateTime>)

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

Explicit(XAttribute to Nullable<DateTimeOffset>) Explicit(XAttribute to Nullable<DateTimeOffset>) Explicit(XAttribute to Nullable<DateTimeOffset>) Explicit(XAttribute to Nullable<DateTimeOffset>)

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

Explicit(XAttribute to Nullable<Decimal>) Explicit(XAttribute to Nullable<Decimal>) Explicit(XAttribute to Nullable<Decimal>) Explicit(XAttribute to Nullable<Decimal>)

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

Explicit(XAttribute to Nullable<Double>) Explicit(XAttribute to Nullable<Double>) Explicit(XAttribute to Nullable<Double>) Explicit(XAttribute to Nullable<Double>)

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

Explicit(XAttribute to Nullable<Guid>) Explicit(XAttribute to Nullable<Guid>) Explicit(XAttribute to Nullable<Guid>) Explicit(XAttribute to Nullable<Guid>)

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

Explicit(XAttribute to Nullable<Int32>) Explicit(XAttribute to Nullable<Int32>) Explicit(XAttribute to Nullable<Int32>) Explicit(XAttribute to Nullable<Int32>)

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

Explicit(XAttribute to Nullable<Int64>) Explicit(XAttribute to Nullable<Int64>) Explicit(XAttribute to Nullable<Int64>) Explicit(XAttribute to Nullable<Int64>)

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

Explicit(XAttribute to Nullable<Single>) Explicit(XAttribute to Nullable<Single>) Explicit(XAttribute to Nullable<Single>) Explicit(XAttribute to Nullable<Single>)

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

Explicit(XAttribute to Nullable<TimeSpan>) Explicit(XAttribute to Nullable<TimeSpan>) Explicit(XAttribute to Nullable<TimeSpan>) Explicit(XAttribute to Nullable<TimeSpan>)

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

Explicit(XAttribute to Nullable<UInt32>) Explicit(XAttribute to Nullable<UInt32>) Explicit(XAttribute to Nullable<UInt32>) Explicit(XAttribute to Nullable<UInt32>)

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

Explicit(XAttribute to Nullable<UInt64>) Explicit(XAttribute to Nullable<UInt64>) Explicit(XAttribute to Nullable<UInt64>) Explicit(XAttribute to Nullable<UInt64>)

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

Explicit(XAttribute to Single) Explicit(XAttribute to Single) Explicit(XAttribute to Single) Explicit(XAttribute to Single)

Cast the value of this XAttribute to a Single.

Explicit(XAttribute to String) Explicit(XAttribute to String) Explicit(XAttribute to String) Explicit(XAttribute to String)

Cast the value of this XAttribute to a String.

Explicit(XAttribute to TimeSpan) Explicit(XAttribute to TimeSpan) Explicit(XAttribute to TimeSpan) Explicit(XAttribute to TimeSpan)

Cast the value of this XAttribute to a TimeSpan.

Explicit(XAttribute to UInt32) Explicit(XAttribute to UInt32) Explicit(XAttribute to UInt32) Explicit(XAttribute to UInt32)

Cast the value of this XAttribute to a UInt32.

Explicit(XAttribute to UInt64) Explicit(XAttribute to UInt64) Explicit(XAttribute to UInt64) Explicit(XAttribute to UInt64)

Cast the value of this XAttribute to a UInt64.

Events

Changed Changed Changed Changed

Raised when this XObject or any of its descendants have changed.

(Inherited from XObject)
Changing Changing Changing Changing

Raised when this XObject or any of its descendants are about to change.

(Inherited from XObject)

Explicit Interface Implementations

IXmlLineInfo.HasLineInfo() IXmlLineInfo.HasLineInfo() IXmlLineInfo.HasLineInfo() IXmlLineInfo.HasLineInfo()

Gets a value indicating whether or not this XObject has line information.

(Inherited from XObject)

Extension Methods

GetSchemaInfo(XAttribute) GetSchemaInfo(XAttribute) GetSchemaInfo(XAttribute) GetSchemaInfo(XAttribute)

Gets the post-schema-validation infoset (PSVI) of a validated attribute.

Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)

This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.

Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler, Boolean) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler, Boolean) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler, Boolean) Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler, Boolean)

Validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet, optionally populating the XML tree with the post-schema-validation infoset (PSVI).

Applies to

See Also