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

取得這個屬性的擴展名稱 (Expanded 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

取得這個 XElementXObjectGets the parent XElement of this XObject.

(繼承來源 XObject)
PreviousAttribute

取得父項目的前一個屬性。Gets the previous attribute of the parent element.

Value

取得或設定此屬性 (Attribute) 的值。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 的淺層複本 (Shallow Copy)。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 是否符合指定的 XmlSchemaObjectXmlSchemaSetThis 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).

適用於

另請參閱