共用方式為


XAttribute 類別

定義

代表一個 XML 屬性。

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 元素相關的名稱/值對。

每個 XElement 屬性都包含該元素的屬性清單。 屬性必須有一個限定且該元素唯一的限定名稱。 屬性並非源自 XNode;它們不是 XML 樹中的節點。 它們只是與元素相關聯的名稱/值對。

屬性會在 XML 樹中依加入元素的順序維護。 當屬性集合被 回 Attributes傳時,屬性會依加入元素的順序回傳,且不會排序。

技術上,在 XML 中,命名空間宣告並非真正的屬性。 然而,許多 XML 程式設計師通常不會做出這種區分。 相反地,由於命名空間宣告與屬性具有完全相同的 XML 語法,大多數 XML 程式設計師將命名空間視為屬性。 為了簡化 LINQ 到 XML 的程式介面,命名空間在 XML 樹中以屬性表示。 這類命名空間屬性會影響 XML 樹的序列化。 序列化時,LINQ 轉 XML 嘗試使用命名空間屬性中指定的命名空間前綴序列化。 你可以用 來 IsNamespaceDeclaration 判斷屬性是否真的是命名空間宣告。

XAttribute 類別衍生自 XObject。 你可以為屬性加上註解,並觀察其事件。

有些 XAttribute 方法可以從 XAML 使用。 如需詳細資訊,請參閱 LINQ to XML 動態屬性

建構函式

名稱 Description
XAttribute(XAttribute)

從另一個XAttribute物件初始化該XAttribute類別的新實例。

XAttribute(XName, Object)

從指定的名稱和值初始化該 XAttribute 類別的新實例。

屬性

名稱 Description
BaseUri

取得基本的 URI 來處理這個 XObject

(繼承來源 XObject)
Document

為此XDocument付出XObject代價。

(繼承來源 XObject)
EmptySequence

獲得一個空屬性集合。

IsNamespaceDeclaration

判斷此屬性是否為命名空間宣告。

Name

獲得此屬性擴展名稱。

NextAttribute

取得父元素的下一個屬性。

NodeType

取得該節點的節點類型。

Parent

得到這個XElement家長XObject

(繼承來源 XObject)
PreviousAttribute

取得父元素的前一個屬性。

Value

取得或設定此屬性的值。

方法

名稱 Description
AddAnnotation(Object)

將物件加入此 XObject標註清單中。

(繼承來源 XObject)
Annotation(Type)

從此 XObject取得指定類型的第一個註解物件。

(繼承來源 XObject)
Annotation<T>()

從此 XObject取得指定類型的第一個註解物件。

(繼承來源 XObject)
Annotations(Type)

會獲得一組指定類型的 XObject註解。

(繼承來源 XObject)
Annotations<T>()

會獲得一組指定類型的 XObject註解。

(繼承來源 XObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Remove()

移除該屬性的父元素。

RemoveAnnotations(Type)

從中 XObject移除指定類型的註解。

(繼承來源 XObject)
RemoveAnnotations<T>()

從中 XObject移除指定類型的註解。

(繼承來源 XObject)
SetValue(Object)

設定此屬性的值。

ToString()

將目前 XAttribute 的物件轉換成字串表示。

操作員

名稱 Description
Explicit(XAttribute to Boolean)

將此XAttributeBoolean值鑄為 。

Explicit(XAttribute to DateTime)

將此XAttributeDateTime值鑄為 。

Explicit(XAttribute to DateTimeOffset)

將此XAttributeDateTimeOffset值鑄為 。

Explicit(XAttribute to Decimal)

將此XAttributeDecimal值鑄為 。

Explicit(XAttribute to Double)

將此XAttributeDouble值鑄為 。

Explicit(XAttribute to Guid)

將此XAttributeGuid值鑄為 。

Explicit(XAttribute to Int32)

將此XAttributeInt32值鑄造成 。

Explicit(XAttribute to Int64)

將此XAttributeInt64值鑄造成 。

Explicit(XAttribute to Nullable<Boolean>)

將此 XAttribute 值鑄為 的 Nullable<T>Boolean

Explicit(XAttribute to Nullable<DateTime>)

將此 XAttribute 值鑄為 的 Nullable<T>DateTime

Explicit(XAttribute to Nullable<DateTimeOffset>)

將此 XAttribute 值鑄為 的 Nullable<T>DateTimeOffset

Explicit(XAttribute to Nullable<Decimal>)

將此 XAttribute 值鑄為 的 Nullable<T>Decimal

Explicit(XAttribute to Nullable<Double>)

將此 XAttribute 值鑄為 的 Nullable<T>Double

Explicit(XAttribute to Nullable<Guid>)

將此 XAttribute 值鑄為 的 Nullable<T>Guid

Explicit(XAttribute to Nullable<Int32>)

將此 XAttribute 值鑄為 的 Nullable<T>Int32

Explicit(XAttribute to Nullable<Int64>)

將此 XAttribute 值鑄為 的 Nullable<T>Int64

Explicit(XAttribute to Nullable<Single>)

將此 XAttribute 值鑄為 的 Nullable<T>Single

Explicit(XAttribute to Nullable<TimeSpan>)

將此 XAttribute 值鑄為 的 Nullable<T>TimeSpan

Explicit(XAttribute to Nullable<UInt32>)

將此 XAttribute 值鑄為 的 Nullable<T>UInt32

Explicit(XAttribute to Nullable<UInt64>)

將此 XAttribute 值鑄為 的 Nullable<T>UInt64

Explicit(XAttribute to Single)

將此XAttributeSingle值鑄為 。

Explicit(XAttribute to String)

將此XAttributeString值鑄為 。

Explicit(XAttribute to TimeSpan)

將此XAttributeTimeSpan值鑄為 。

Explicit(XAttribute to UInt32)

將此XAttributeUInt32值鑄為 。

Explicit(XAttribute to UInt64)

將此XAttributeUInt64值鑄為 。

事件

名稱 Description
Changed

當這個 XObject 或其後代改變時,他會被養育。

(繼承來源 XObject)
Changing

當這個 XObject 或其後代即將改變時,他被養育。

(繼承來源 XObject)

明確介面實作

名稱 Description
IXmlLineInfo.HasLineInfo()

會獲得一個值,表示該項目 XObject 是否有行資訊。

(繼承來源 XObject)
IXmlLineInfo.LineNumber

取得標的資產 XmlReader 報告 XObject的行號。

(繼承來源 XObject)
IXmlLineInfo.LinePosition

取得標的資產 XmlReader 報告 XObject的線位。

(繼承來源 XObject)

擴充方法

名稱 Description
GetSchemaInfo(XAttribute)

取得驗證屬性的後 schema-validation 資訊集(PSVI)。

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

驗證 a XAttribute 是否符合指定的 XmlSchemaObjectXmlSchemaSet,並可選擇性地將 XML 樹填充後 schema-validation 資訊集(PSVI)。

Validate(XAttribute, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)

此方法驗證 a XAttribute 符合指定XmlSchemaObjectXmlSchemaSet且 。

適用於

另請參閱