XAttribute Class
Represents an XML attribute.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
| Name | Description | |
|---|---|---|
![]() | XAttribute(XAttribute^) | Initializes a new instance of the XAttribute class from another XAttribute object. |
![]() | XAttribute(XName^, Object^) | Initializes a new instance of the XAttribute class from the specified name and value. |
| Name | Description | |
|---|---|---|
![]() | BaseUri | |
![]() | Document | |
![]() ![]() | EmptySequence | Gets an empty collection of attributes. |
![]() | IsNamespaceDeclaration | Determines if this attribute is a namespace declaration. |
![]() | Name | Gets the expanded name of this attribute. |
![]() | NextAttribute | Gets the next attribute of the parent element. |
![]() | NodeType | Gets the node type for this node.(Overrides XObject::NodeType.) |
![]() | Parent | |
![]() | PreviousAttribute | Gets the previous attribute of the parent element. |
![]() | Value | Gets or sets the value of this attribute. |
| Name | Description | |
|---|---|---|
![]() | AddAnnotation(Object^) | |
![]() | Annotation(Type^) | |
![]() | Annotation<T>() | |
![]() | Annotations(Type^) | |
![]() | Annotations<T>() | |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | Remove() | Removes this attribute from its parent element. |
![]() | RemoveAnnotations(Type^) | |
![]() | RemoveAnnotations<T>() | |
![]() | SetValue(Object^) | Sets the value of this attribute. |
![]() | ToString() | Converts the current XAttribute object to a string representation.(Overrides Object::ToString().) |
| Name | Description | |
|---|---|---|
![]() | GetSchemaInfo() | Overloaded. Gets the post-schema-validation infoset (PSVI) of a validated attribute.(Defined by Extensions.) |
![]() | Validate(XmlSchemaObject^, XmlSchemaSet^, ValidationEventHandler^) | Overloaded. This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.(Defined by Extensions.) |
![]() | 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.) |
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.
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.








