XAttribute 类

定义

表示 XML 特性。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
继承
XAttribute

注解

XML 特性是与 XML 元素关联的名称/值对。An XML attribute is a name/value pair associated with an XML element.

每个 XElement 都包含该元素的属性列表。Each XElement contains a list of the attributes for that element. 特性必须具有元素唯一的限定名称。Attributes must have a qualified name that is unique to the element. 特性不是派生自 XNode;它们不是 XML 树中的节点。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.

属性在 XML 树中按其添加到元素中的顺序进行维护。Attributes are maintained in the XML tree in the order that they were added to the element. Attributes返回特性的集合时,它们将按照添加到元素中的顺序返回,且不会进行排序。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.

从技术上说,在 XML 中,命名空间声明不是正确的特性。Technically, in XML, namespace declarations are not attributes proper. 但是,很多 XML 程序员通常不会对此进行区分。However, this distinction is not normally made by many XML programmers. 相反,因为命名空间声明与特性具有完全相同的 XML 语法,所以大多数 XML 编程人员将命名空间视为属性。Instead, because namespace declarations have exactly the same XML syntax as attributes, most XML programmers think of namespaces as attributes. 为了简化 LINQ to XMLLINQ to XML 编程接口,命名空间在 XML 树中表示为属性。To simplify the LINQ to XMLLINQ to XML programming interface, namespaces are represented in the XML tree as attributes. 此类命名空间特性会影响 XML 树的序列化。Such namespace attributes impact serialization of an XML tree. 序列化时,LINQ to XMLLINQ to XML 会尝试通过命名空间特性中指定的命名空间前缀来序列化。When serializing, LINQ to XMLLINQ to XML attempts to serialize with the namespace prefix specified in namespace attributes. 您可以使用 IsNamespaceDeclaration 来确定属性是否确实为命名空间声明。You can use the IsNamespaceDeclaration to determine if an attribute is really a namespace declaration.

XAttribute 类派生自 XObjectThe XAttribute class derives from XObject. 您可以向属性添加批注,并观察它们的事件。You can add annotations to attributes, and observe events for them.

某些 XAttribute 方法可从 XAML 使用。Some XAttribute methods can be used from XAML. 有关详细信息,请参阅 LINQ to XML 动态属性For more information, see LINQ to XML Dynamic Properties.

构造函数

XAttribute(XAttribute)

从另一个 XAttribute 对象初始化 XAttribute 类的新实例。Initializes a new instance of the XAttribute class from another XAttribute object.

XAttribute(XName, Object)

从指定的名称和值初始化 XAttribute 类的新实例。Initializes a new instance of the XAttribute class from the specified name and value.

属性

BaseUri

获取此 XObject 的基 URI。Gets the base URI for this XObject.

(继承自 XObject)
Document

获取此 XDocumentXObjectGets the XDocument for this XObject.

(继承自 XObject)
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.

Parent

获取此 XElement 的父级 XObjectGets the parent XElement of this XObject.

(继承自 XObject)
PreviousAttribute

获取父元素的上一个属性。Gets the previous attribute of the parent element.

Value

获取或设置此属性的值。Gets or sets the value of this attribute.

方法

AddAnnotation(Object)

将对象添加到此 XObject 的批注列表。Adds an object to the annotation list of this XObject.

(继承自 XObject)
Annotation(Type)

从此 XObject 获取指定类型的第一个批注对象。Gets the first annotation object of the specified type from this XObject.

(继承自 XObject)
Annotation<T>()

从此 XObject 获取指定类型的第一个批注对象。Gets the first annotation object of the specified type from this XObject.

(继承自 XObject)
Annotations(Type)

获取此 XObject 的指定类型的批注集合。Gets a collection of annotations of the specified type for this XObject.

(继承自 XObject)
Annotations<T>()

获取此 XObject 的指定类型的批注集合。Gets a collection of annotations of the specified type for this XObject.

(继承自 XObject)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove()

将此属性从父元素中移除。Removes this attribute from its parent element.

RemoveAnnotations(Type)

从此 XObject 移除指定类型的批注。Removes the annotations of the specified type from this XObject.

(继承自 XObject)
RemoveAnnotations<T>()

从此 XObject 移除指定类型的批注。Removes the annotations of the specified type from this XObject.

(继承自 XObject)
SetValue(Object)

设置此属性的值。Sets the value of this attribute.

ToString()

将当前的 XAttribute 对象转换为字符串表示形式。Converts the current XAttribute object to a string representation.

运算符

Explicit(XAttribute to Boolean)

将此 XAttribute 的值强制转换为 BooleanCast the value of this XAttribute to a Boolean.

Explicit(XAttribute to DateTime)

将此 XAttribute 的值强制转换为 DateTimeCast the value of this XAttribute to a DateTime.

Explicit(XAttribute to DateTimeOffset)

将此 XAttribute 的值强制转换为 DateTimeOffsetCast the value of this XAttribute to a DateTimeOffset.

Explicit(XAttribute to Decimal)

将此 XAttribute 的值强制转换为 DecimalCast the value of this XAttribute to a Decimal.

Explicit(XAttribute to Double)

将此 XAttribute 的值强制转换为 DoubleCast the value of this XAttribute to a Double.

Explicit(XAttribute to Guid)

将此 XAttribute 的值强制转换为 GuidCast the value of this XAttribute to a Guid.

Explicit(XAttribute to Int32)

将此 XAttribute 的值强制转换为 Int32Cast the value of this XAttribute to an Int32.

Explicit(XAttribute to Int64)

将此 XAttribute 的值强制转换为 Int64Cast the value of this XAttribute to an Int64.

Explicit(XAttribute to Nullable<Boolean>)

将此 XAttribute 的值强制转换为 Nullable<T>BooleanCast the value of this XAttribute to a Nullable<T> of Boolean.

Explicit(XAttribute to Nullable<DateTime>)

将此 XAttribute 的值强制转换为 Nullable<T>DateTimeCast the value of this XAttribute to a Nullable<T> of DateTime.

Explicit(XAttribute to Nullable<DateTimeOffset>)

将此 XAttribute 的值强制转换为 Nullable<T>DateTimeOffsetCast the value of this XAttribute to a Nullable<T> of DateTimeOffset.

Explicit(XAttribute to Nullable<Decimal>)

将此 XAttribute 的值强制转换为 Nullable<T>DecimalCast the value of this XAttribute to a Nullable<T> of Decimal.

Explicit(XAttribute to Nullable<Double>)

将此 XAttribute 的值强制转换为 Nullable<T>DoubleCast the value of this XAttribute to a Nullable<T> of Double.

Explicit(XAttribute to Nullable<Guid>)

将此 XAttribute 的值强制转换为 Nullable<T>GuidCast the value of this XAttribute to a Nullable<T> of Guid.

Explicit(XAttribute to Nullable<Int32>)

将此 XAttribute 的值强制转换为 Nullable<T>Int32Cast the value of this XAttribute to a Nullable<T> of Int32.

Explicit(XAttribute to Nullable<Int64>)

将此 XAttribute 的值强制转换为 Nullable<T>Int64Cast the value of this XAttribute to a Nullable<T> of Int64.

Explicit(XAttribute to Nullable<Single>)

将此 XAttribute 的值强制转换为 Nullable<T>SingleCast the value of this XAttribute to a Nullable<T> of Single.

Explicit(XAttribute to Nullable<TimeSpan>)

将此 XAttribute 的值强制转换为 Nullable<T>TimeSpanCast the value of this XAttribute to a Nullable<T> of TimeSpan.

Explicit(XAttribute to Nullable<UInt32>)

将此 XAttribute 的值强制转换为 Nullable<T>UInt32Cast the value of this XAttribute to a Nullable<T> of UInt32.

Explicit(XAttribute to Nullable<UInt64>)

将此 XAttribute 的值强制转换为 Nullable<T>UInt64Cast the value of this XAttribute to a Nullable<T> of UInt64.

Explicit(XAttribute to Single)

将此 XAttribute 的值强制转换为 SingleCast the value of this XAttribute to a Single.

Explicit(XAttribute to String)

将此 XAttribute 的值强制转换为 StringCast the value of this XAttribute to a String.

Explicit(XAttribute to TimeSpan)

将此 XAttribute 的值强制转换为 TimeSpanCast the value of this XAttribute to a TimeSpan.

Explicit(XAttribute to UInt32)

将此 XAttribute 的值强制转换为 UInt32Cast the value of this XAttribute to a UInt32.

Explicit(XAttribute to UInt64)

将此 XAttribute 的值强制转换为 UInt64Cast the value of this XAttribute to a UInt64.

事件

Changed

在此 XObject 或其任何子代发生了更改时引发。Raised when this XObject or any of its descendants have changed.

(继承自 XObject)
Changing

当此 XObject 或其任何子代要发生更改时引发。Raised when this XObject or any of its descendants are about to change.

(继承自 XObject)

显式接口实现

IXmlLineInfo.HasLineInfo()

获取一个值,该值指示此 XObject 是否具有行信息。Gets a value indicating whether or not this XObject has line information.

(继承自 XObject)
IXmlLineInfo.LineNumber

获取基础 XmlReader 为此 XObject 报告的行号。Gets the line number that the underlying XmlReader reported for this XObject.

(继承自 XObject)
IXmlLineInfo.LinePosition

获取基础 XmlReader 为此 XObject 报告的行位置。Gets the line position that the underlying XmlReader reported for this XObject.

(继承自 XObject)

扩展方法

GetSchemaInfo(XAttribute)

获取已验证特性的架构验证后信息集 (PSVI)。Gets the post-schema-validation infoset (PSVI) of a validated attribute.

Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)

此方法验证 XAttribute 是否与指定的 XmlSchemaObjectXmlSchemaSet 相符。This method validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet.

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

验证 XAttribute 是否与指定的 XmlSchemaObjectXmlSchemaSet 相符,并且可以选择使用架构验证后信息集 (PSVI) 填充 XML 树。Validates that an XAttribute conforms to a specified XmlSchemaObject and an XmlSchemaSet, optionally populating the XML tree with the post-schema-validation infoset (PSVI).

适用于

另请参阅