XElement XElement XElement XElement Class

定義

表示 XML 項目。Represents an XML element. 如需用法資訊和範例,請參閱 XElement 類別概觀及本頁面上的<備註>一節。See XElement Class Overview and the Remarks section on this page for usage information and examples.

public ref class XElement : System::Xml::Linq::XContainer, System::Xml::Serialization::IXmlSerializable
public class XElement : System.Xml.Linq.XContainer, System.Xml.Serialization.IXmlSerializable
type XElement = class
    inherit XContainer
    interface IXmlSerializable
Public Class XElement
Inherits XContainer
Implements IXmlSerializable
繼承
實作

範例

下列範例會建立 XML 樹狀結構。The following example creates an XML tree. 新元素的內容來自 LINQ 查詢。The content of the new element comes from a LINQ query.

XElement xmlTree1 = new XElement("Root",  
    new XElement("Child1", 1),  
    new XElement("Child2", 2),  
    new XElement("Child3", 3),  
    new XElement("Child4", 4),  
    new XElement("Child5", 5),  
    new XElement("Child6", 6)  
);  
  
XElement xmlTree2 = new XElement("Root",  
    from el in xmlTree1.Elements()  
    where((int)el >= 3 && (int)el <= 5)  
    select el  
);  
Console.WriteLine(xmlTree2);  
Dim xmlTree1 As XElement = _  
        <Root>  
            <Child1>1</Child1>  
            <Child2>2</Child2>  
            <Child3>3</Child3>  
            <Child4>4</Child4>  
            <Child5>5</Child5>  
            <Child6>6</Child6>  
        </Root>  
  
Dim xmlTree2 As XElement = _   
    <Root>  
        <%= From el In xmlTree1.Elements() _  
            Where el.Value >= 3 And el.Value <= 5 _  
            Select el %>  
    </Root>  
  
Console.WriteLine(xmlTree2)  

這個範例會產生下列輸出:This example produces the following output:

<Root>  
  <Child3>3</Child3>  
  <Child4>4</Child4>  
  <Child5>5</Child5>  
</Root>  

下列是相同的範例,但在此情況下,XML 是在命名空間中。The following is the same example, but in this case the XML is in a namespace. 如需詳細資訊,請參閱使用 XML 命名空間For more information, see Working with XML Namespaces.

XNamespace aw = "http://www.adventure-works.com";  
XElement xmlTree1 = new XElement(aw + "Root",  
    new XElement(aw + "Child1", 1),  
    new XElement(aw + "Child2", 2),  
    new XElement(aw + "Child3", 3),  
    new XElement(aw + "Child4", 4),  
    new XElement(aw + "Child5", 5),  
    new XElement(aw + "Child6", 6)  
);  
  
XElement xmlTree2 = new XElement(aw + "Root",  
    from el in xmlTree1.Elements()  
    where((int)el >= 3 && (int)el <= 5)  
    select el  
);  
Console.WriteLine(xmlTree2);  
Imports <xmlns="http://www.adventure-works.com">  
  
Module Module1  
    Sub Main()  
        Dim xmlTree1 As XElement = _  
            <Root>  
                <Child1>1</Child1>  
                <Child2>2</Child2>  
                <Child3>3</Child3>  
                <Child4>4</Child4>  
                <Child5>5</Child5>  
                <Child6>6</Child6>  
            </Root>  
  
        Dim xmlTree2 As XElement = _   
            <Root>  
                <%= From el In xmlTree1.Elements() _  
                    Where el.Value >= 3 And el.Value <= 5 _  
                    Select el %>  
            </Root>  
  
        Console.WriteLine(xmlTree2)  
    End SUb  
End Module  

這個範例會產生下列輸出:This example produces the following output:

<Root xmlns="http://www.adventure-works.com">  
  <Child3>3</Child3>  
  <Child4>4</Child4>  
  <Child5>5</Child5>  
</Root>  

備註

此類別代表 XML 元素,這是基本 XML 結構。This class represents an XML element, the fundamental XML construct. 如需其他使用方式資訊,請參閱System.xml.linq.xelement> 類別總覽See XElement Class Overview for other usage information.

元素具有 XName,選擇性的一個或多個屬性,而且可以選擇性地包含內容(如需詳細資訊,請參閱 Nodes)。An element has an XName, optionally one or more attributes, and can optionally contain content (for more information, see Nodes).

@No__t-0 可以包含下列類型的內容:An XElement can contain the following types of content:

如需 XElement 之有效內容的詳細資訊,請參閱system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content of an XElement, see Valid Content of XElement and XDocument Objects.

XElement 衍生自 XNodeXContainerXElement derives from XContainer, which derives from XNode.

有些 XElement 方法可以從 XAML 使用。Some XElement methods can be used from XAML. 如需詳細資訊,請參閱 LINQ to XML 動態屬性For more information, see LINQ to XML Dynamic Properties.

建構函式

XElement(XElement) XElement(XElement) XElement(XElement) XElement(XElement)

從另一個 XElement 物件,初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class from another XElement object.

XElement(XName) XElement(XName) XElement(XName) XElement(XName)

使用指定的名稱,初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class with the specified name.

XElement(XName, Object) XElement(XName, Object) XElement(XName, Object) XElement(XName, Object)

使用指定的名稱和內容初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class with the specified name and content.

XElement(XName, Object[]) XElement(XName, Object[]) XElement(XName, Object[]) XElement(XName, Object[])

使用指定的名稱和內容初始化 XElement 類別的新執行個體。Initializes a new instance of the XElement class with the specified name and content.

XElement(XStreamingElement) XElement(XStreamingElement) XElement(XStreamingElement) XElement(XStreamingElement)

XElement 物件初始化 XStreamingElement 類別的新執行個體。Initializes a new instance of the XElement class from an XStreamingElement object.

屬性

BaseUri BaseUri BaseUri BaseUri

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

(Inherited from XObject)
Document Document Document Document

取得此 XDocumentXObjectGets the XDocument for this XObject.

(Inherited from XObject)
EmptySequence EmptySequence EmptySequence EmptySequence

取得空的項目集合。Gets an empty collection of elements.

FirstAttribute FirstAttribute FirstAttribute FirstAttribute

取得這個項目的第一個屬性。Gets the first attribute of this element.

FirstNode FirstNode FirstNode FirstNode

取得此節點的第一個子節點。Gets the first child node of this node.

(Inherited from XContainer)
HasAttributes HasAttributes HasAttributes HasAttributes

取得值,指出這個項目是否至少有一個屬性。Gets a value indicating whether this element has at least one attribute.

HasElements HasElements HasElements HasElements

取得值,指出這個項目是否至少有一個子項目。Gets a value indicating whether this element has at least one child element.

IsEmpty IsEmpty IsEmpty IsEmpty

取得值,指出這個項目是否不包含內容。Gets a value indicating whether this element contains no content.

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

取得基礎 XmlReader 所回報此 XObject 的行號。Gets the line number that the underlying XmlReader reported for this XObject.

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

取得基礎 XmlReader 所報告之此 XObject 的行位置。Gets the line position that the underlying XmlReader reported for this XObject.

(Inherited from XObject)
LastAttribute LastAttribute LastAttribute LastAttribute

取得這個項目的最後一個屬性。Gets the last attribute of this element.

LastNode LastNode LastNode LastNode

取得此節點的最後一個子節點。Gets the last child node of this node.

(Inherited from XContainer)
Name Name Name Name

取得或設定這個元素的名稱。Gets or sets the name of this element.

NextNode NextNode NextNode NextNode

取得這個節點的下一個同層級 (Sibling) 節點。Gets the next sibling node of this node.

(Inherited from XNode)
NodeType NodeType NodeType NodeType

取得此節點的節點類型。Gets the node type for this node.

Parent Parent Parent Parent

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

(Inherited from XObject)
PreviousNode PreviousNode PreviousNode PreviousNode

取得這個節點的上一個同層級節點。Gets the previous sibling node of this node.

(Inherited from XNode)
Value Value Value Value

取得或設定這個元素的串連文字內容。Gets or sets the concatenated text contents of this element.

方法

Add(Object) Add(Object) Add(Object) Add(Object)

加入指定的內容做為此 XContainer 的子系。Adds the specified content as children of this XContainer.

(Inherited from XContainer)
Add(Object[]) Add(Object[]) Add(Object[]) Add(Object[])

加入指定的內容做為此 XContainer 的子系。Adds the specified content as children of this XContainer.

(Inherited from XContainer)
AddAfterSelf(Object) AddAfterSelf(Object) AddAfterSelf(Object) AddAfterSelf(Object)

將指定的內容加入緊接在此節點後面的位置。Adds the specified content immediately after this node.

(Inherited from XNode)
AddAfterSelf(Object[]) AddAfterSelf(Object[]) AddAfterSelf(Object[]) AddAfterSelf(Object[])

將指定的內容加入緊接在此節點後面的位置。Adds the specified content immediately after this node.

(Inherited from XNode)
AddAnnotation(Object) AddAnnotation(Object) AddAnnotation(Object) AddAnnotation(Object)

將物件加入此 XObject 的註釋清單。Adds an object to the annotation list of this XObject.

(Inherited from XObject)
AddBeforeSelf(Object) AddBeforeSelf(Object) AddBeforeSelf(Object) AddBeforeSelf(Object)

將指定的內容加入緊接在此節點前面的位置。Adds the specified content immediately before this node.

(Inherited from XNode)
AddBeforeSelf(Object[]) AddBeforeSelf(Object[]) AddBeforeSelf(Object[]) AddBeforeSelf(Object[])

將指定的內容加入緊接在此節點前面的位置。Adds the specified content immediately before this node.

(Inherited from XNode)
AddFirst(Object) AddFirst(Object) AddFirst(Object) AddFirst(Object)

加入指定的內容,以當做此文件或項目的第一個子系。Adds the specified content as the first children of this document or element.

(Inherited from XContainer)
AddFirst(Object[]) AddFirst(Object[]) AddFirst(Object[]) AddFirst(Object[])

加入指定的內容,以當做此文件或項目的第一個子系。Adds the specified content as the first children of this document or element.

(Inherited from XContainer)
Ancestors() Ancestors() Ancestors() Ancestors()

傳回這個節點之祖系項目的集合。Returns a collection of the ancestor elements of this node.

(Inherited from XNode)
Ancestors(XName) Ancestors(XName) Ancestors(XName) Ancestors(XName)

傳回這個節點的祖系項目之篩選的集合。Returns a filtered collection of the ancestor elements of this node. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

(Inherited from XNode)
AncestorsAndSelf() AncestorsAndSelf() AncestorsAndSelf() AncestorsAndSelf()

傳回包含這個元素的元素集合,以及這個元素的上階。Returns a collection of elements that contain this element, and the ancestors of this element.

AncestorsAndSelf(XName) AncestorsAndSelf(XName) AncestorsAndSelf(XName) AncestorsAndSelf(XName)

傳回包含這個項目的已篩選項目集合,以及這個項目的祖系。Returns a filtered collection of elements that contain this element, and the ancestors of this element. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Annotation(Type) Annotation(Type) Annotation(Type) Annotation(Type)

從此 XObject 取得指定類型的第一個註釋物件。Gets the first annotation object of the specified type from this XObject.

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

從此 XObject 取得指定類型的第一個註釋物件。Gets the first annotation object of the specified type from this XObject.

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

取得此 XObject 之指定類型註釋的集合。Gets a collection of annotations of the specified type for this XObject.

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

取得此 XObject 之指定類型註釋的集合。Gets a collection of annotations of the specified type for this XObject.

(Inherited from XObject)
Attribute(XName) Attribute(XName) Attribute(XName) Attribute(XName)

傳回這個 XAttributeXElement,其具有指定的 XNameReturns the XAttribute of this XElement that has the specified XName.

Attributes() Attributes() Attributes() Attributes()

傳回這個元素的屬性集合。Returns a collection of attributes of this element.

Attributes(XName) Attributes(XName) Attributes(XName) Attributes(XName)

傳回這個項目的已篩選屬性集合。Returns a filtered collection of attributes of this element. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

CreateReader() CreateReader() CreateReader() CreateReader()

建立這個節點的 XmlReaderCreates an XmlReader for this node.

(Inherited from XNode)
CreateReader(ReaderOptions) CreateReader(ReaderOptions) CreateReader(ReaderOptions) CreateReader(ReaderOptions)

使用 readerOptions 參數指定的選項建立 XmlReaderCreates an XmlReader with the options specified by the readerOptions parameter.

(Inherited from XNode)
CreateWriter() CreateWriter() CreateWriter() CreateWriter()

建立可以用來將節點加入到 XmlWriterXContainerCreates an XmlWriter that can be used to add nodes to the XContainer.

(Inherited from XContainer)
DescendantNodes() DescendantNodes() DescendantNodes() DescendantNodes()

依照文件順序,傳回這個文件或項目之子代節點的集合。Returns a collection of the descendant nodes for this document or element, in document order.

(Inherited from XContainer)
DescendantNodesAndSelf() DescendantNodesAndSelf() DescendantNodesAndSelf() DescendantNodesAndSelf()

依照文件順序,傳回包含這個項目的節點集合,以及這個項目的所有子代節點。Returns a collection of nodes that contain this element, and all descendant nodes of this element, in document order.

Descendants() Descendants() Descendants() Descendants()

依照文件順序,傳回這個項目或文件之子代項目的集合。Returns a collection of the descendant elements for this document or element, in document order.

(Inherited from XContainer)
Descendants(XName) Descendants(XName) Descendants(XName) Descendants(XName)

依照文件順序,傳回這個文件或項目之已篩選子代項目的集合。Returns a filtered collection of the descendant elements for this document or element, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

(Inherited from XContainer)
DescendantsAndSelf() DescendantsAndSelf() DescendantsAndSelf() DescendantsAndSelf()

依照文件順序,傳回包含這個項目的項目集合,以及這個項目的子代項目。Returns a collection of elements that contain this element, and all descendant elements of this element, in document order.

DescendantsAndSelf(XName) DescendantsAndSelf(XName) DescendantsAndSelf(XName) DescendantsAndSelf(XName)

依照文件順序,傳回包含這個項目的已篩選項目集合,以及這個項目的所有子代項目。Returns a filtered collection of elements that contain this element, and all descendant elements of this element, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Element(XName) Element(XName) Element(XName) Element(XName)

取得具有指定之 XName 的第一個 (依據文件順序) 子項目。Gets the first (in document order) child element with the specified XName.

(Inherited from XContainer)
Elements() Elements() Elements() Elements()

依照文件順序,傳回這個項目或文件之子代項目的集合。Returns a collection of the child elements of this element or document, in document order.

(Inherited from XContainer)
Elements(XName) Elements(XName) Elements(XName) Elements(XName)

依照文件順序,傳回這個項目或文件之已篩選子代項目的集合。Returns a filtered collection of the child elements of this element or document, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

(Inherited from XContainer)
ElementsAfterSelf() ElementsAfterSelf() ElementsAfterSelf() ElementsAfterSelf()

依照文件順序,傳回這個節點之後同層級項目的集合。Returns a collection of the sibling elements after this node, in document order.

(Inherited from XNode)
ElementsAfterSelf(XName) ElementsAfterSelf(XName) ElementsAfterSelf(XName) ElementsAfterSelf(XName)

依照文件順序,傳回這個節點之後同層級項目之篩選的集合。Returns a filtered collection of the sibling elements after this node, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

(Inherited from XNode)
ElementsBeforeSelf() ElementsBeforeSelf() ElementsBeforeSelf() ElementsBeforeSelf()

依照文件順序,傳回這個節點之前同層級項目的集合。Returns a collection of the sibling elements before this node, in document order.

(Inherited from XNode)
ElementsBeforeSelf(XName) ElementsBeforeSelf(XName) ElementsBeforeSelf(XName) ElementsBeforeSelf(XName)

依照文件順序,傳回這個節點之前同層級項目之篩選的集合。Returns a filtered collection of the sibling elements before this node, in document order. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

(Inherited from XNode)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDefaultNamespace() GetDefaultNamespace() GetDefaultNamespace() GetDefaultNamespace()

取得這個 XNamespace 的預設 XElementGets the default XNamespace of this XElement.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String) GetNamespaceOfPrefix(String)

取得與這個 XElement 之特定前置詞相關聯的命名空間。Gets the namespace associated with a particular prefix for this XElement.

GetPrefixOfNamespace(XNamespace) GetPrefixOfNamespace(XNamespace) GetPrefixOfNamespace(XNamespace) GetPrefixOfNamespace(XNamespace)

取得與這個 XElement 之命名空間相關聯的前置詞。Gets the prefix associated with a namespace for this XElement.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsAfter(XNode) IsAfter(XNode) IsAfter(XNode) IsAfter(XNode)

根據文件順序,判斷目前的節點是否出現在指定的節點之後。Determines if the current node appears after a specified node in terms of document order.

(Inherited from XNode)
IsBefore(XNode) IsBefore(XNode) IsBefore(XNode) IsBefore(XNode)

根據文件順序,判斷目前的節點是否出現在指定的節點之前。Determines if the current node appears before a specified node in terms of document order.

(Inherited from XNode)
Load(Stream) Load(Stream) Load(Stream) Load(Stream)

使用指定的資料流,建立新的 XElement 執行個體。Creates a new XElement instance by using the specified stream.

Load(Stream, LoadOptions) Load(Stream, LoadOptions) Load(Stream, LoadOptions) Load(Stream, LoadOptions)

使用指定的資料流建立新的 XElement 執行個體,並選擇性地保留空白字元、設定基底 URI,以及保留行資訊。Creates a new XElement instance by using the specified stream, optionally preserving white space, setting the base URI, and retaining line information.

Load(String) Load(String) Load(String) Load(String)

從檔案載入 XElementLoads an XElement from a file.

Load(String, LoadOptions) Load(String, LoadOptions) Load(String, LoadOptions) Load(String, LoadOptions)

從檔案載入 XElement,並選擇性地保留泛空白字元、設定基底 URI,以及保留行資訊。Loads an XElement from a file, optionally preserving white space, setting the base URI, and retaining line information.

Load(TextReader) Load(TextReader) Load(TextReader) Load(TextReader)

XElement 載入 TextReaderLoads an XElement from a TextReader.

Load(TextReader, LoadOptions) Load(TextReader, LoadOptions) Load(TextReader, LoadOptions) Load(TextReader, LoadOptions)

XElement 載入 TextReader,並選擇性地保留泛空白字元和行資訊。Loads an XElement from a TextReader, optionally preserving white space and retaining line information.

Load(XmlReader) Load(XmlReader) Load(XmlReader) Load(XmlReader)

XElement 載入 XmlReaderLoads an XElement from an XmlReader.

Load(XmlReader, LoadOptions) Load(XmlReader, LoadOptions) Load(XmlReader, LoadOptions) Load(XmlReader, LoadOptions)

XElement 載入 XmlReader,並選擇性地保留泛空白字元、設定基底 URI,以及保留行資訊。Loads an XElement from an XmlReader, optionally preserving white space, setting the base URI, and retaining line information.

LoadAsync(Stream, LoadOptions, CancellationToken) LoadAsync(Stream, LoadOptions, CancellationToken) LoadAsync(Stream, LoadOptions, CancellationToken) LoadAsync(Stream, LoadOptions, CancellationToken)

以非同步方式建立新的 XElement,並使用指定的串流來將其基礎 XML 樹狀結構初始化 (選擇性地保留空白字元)。Asynchronously creates a new XElement and initializes its underlying XML tree using the specified stream, optionally preserving white space.

LoadAsync(TextReader, LoadOptions, CancellationToken) LoadAsync(TextReader, LoadOptions, CancellationToken) LoadAsync(TextReader, LoadOptions, CancellationToken) LoadAsync(TextReader, LoadOptions, CancellationToken)

以非同步方式建立新的 XElement,並使用指定的文字讀取器來將其基礎 XML 樹狀結構初始化 (選擇性地保留空白字元)。Asynchronously creates a new XElement and initializes its underlying XML tree using the specified text reader, optionally preserving white space.

LoadAsync(XmlReader, LoadOptions, CancellationToken) LoadAsync(XmlReader, LoadOptions, CancellationToken) LoadAsync(XmlReader, LoadOptions, CancellationToken) LoadAsync(XmlReader, LoadOptions, CancellationToken)

以非同步方式建立新的 XElement,並使用指定的 XML 讀取器來將其基礎 XML 樹狀結構初始化 (選擇性地保留空白字元)。Asynchronously creates a new XElement and initializes its underlying XML tree using the specified XML reader, optionally preserving white space.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Nodes() Nodes() Nodes() Nodes()

依照文件順序,傳回這個項目或文件之子代節點的集合。Returns a collection of the child nodes of this element or document, in document order.

(Inherited from XContainer)
NodesAfterSelf() NodesAfterSelf() NodesAfterSelf() NodesAfterSelf()

依照文件順序,傳回這個節點之後同層級節點的集合。Returns a collection of the sibling nodes after this node, in document order.

(Inherited from XNode)
NodesBeforeSelf() NodesBeforeSelf() NodesBeforeSelf() NodesBeforeSelf()

依照文件順序,傳回這個節點之前同層級節點的集合。Returns a collection of the sibling nodes before this node, in document order.

(Inherited from XNode)
Parse(String) Parse(String) Parse(String) Parse(String)

從包含 XML 的字串載入 XElementLoad an XElement from a string that contains XML.

Parse(String, LoadOptions) Parse(String, LoadOptions) Parse(String, LoadOptions) Parse(String, LoadOptions)

從包含 XML 的字串載入 XElement,並選擇性地保留泛空白字元和程式行資訊。Load an XElement from a string that contains XML, optionally preserving white space and retaining line information.

Remove() Remove() Remove() Remove()

將這個節點從其父代 (Parent) 移除。Removes this node from its parent.

(Inherited from XNode)
RemoveAll() RemoveAll() RemoveAll() RemoveAll()

從這個 XElement 移除節點及屬性。Removes nodes and attributes from this XElement.

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

從這個 XObject 中移除指定之類型的註釋。Removes the annotations of the specified type from this XObject.

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

從這個 XObject 中移除指定之類型的註釋。Removes the annotations of the specified type from this XObject.

(Inherited from XObject)
RemoveAttributes() RemoveAttributes() RemoveAttributes() RemoveAttributes()

移除這個 XElement 的屬性。Removes the attributes of this XElement.

RemoveNodes() RemoveNodes() RemoveNodes() RemoveNodes()

從此文件或項目中移除子節點。Removes the child nodes from this document or element.

(Inherited from XContainer)
ReplaceAll(Object) ReplaceAll(Object) ReplaceAll(Object) ReplaceAll(Object)

以指定的內容取代這個元素的子節點和屬性。Replaces the child nodes and the attributes of this element with the specified content.

ReplaceAll(Object[]) ReplaceAll(Object[]) ReplaceAll(Object[]) ReplaceAll(Object[])

以指定的內容取代這個元素的子節點和屬性。Replaces the child nodes and the attributes of this element with the specified content.

ReplaceAttributes(Object) ReplaceAttributes(Object) ReplaceAttributes(Object) ReplaceAttributes(Object)

以指定的內容取代這個元素的屬性。Replaces the attributes of this element with the specified content.

ReplaceAttributes(Object[]) ReplaceAttributes(Object[]) ReplaceAttributes(Object[]) ReplaceAttributes(Object[])

以指定的內容取代這個元素的屬性。Replaces the attributes of this element with the specified content.

ReplaceNodes(Object) ReplaceNodes(Object) ReplaceNodes(Object) ReplaceNodes(Object)

以指定的內容取代這個文件或項目的子節點。Replaces the children nodes of this document or element with the specified content.

(Inherited from XContainer)
ReplaceNodes(Object[]) ReplaceNodes(Object[]) ReplaceNodes(Object[]) ReplaceNodes(Object[])

以指定的內容取代這個文件或項目的子節點。Replaces the children nodes of this document or element with the specified content.

(Inherited from XContainer)
ReplaceWith(Object) ReplaceWith(Object) ReplaceWith(Object) ReplaceWith(Object)

以指定的內容取代這個節點。Replaces this node with the specified content.

(Inherited from XNode)
ReplaceWith(Object[]) ReplaceWith(Object[]) ReplaceWith(Object[]) ReplaceWith(Object[])

以指定的內容取代這個節點。Replaces this node with the specified content.

(Inherited from XNode)
Save(Stream) Save(Stream) Save(Stream) Save(Stream)

將這個 XElement 輸出到指定的 StreamOutputs this XElement to the specified Stream.

Save(Stream, SaveOptions) Save(Stream, SaveOptions) Save(Stream, SaveOptions) Save(Stream, SaveOptions)

將這個 XElement 輸出至指定的 Stream,選擇性地指定格式化行為。Outputs this XElement to the specified Stream, optionally specifying formatting behavior.

Save(String) Save(String) Save(String) Save(String)

將這個元素序列化成檔案。Serialize this element to a file.

Save(String, SaveOptions) Save(String, SaveOptions) Save(String, SaveOptions) Save(String, SaveOptions)

將這個元素序列化成檔案 (可選擇是否停用格式設定)。Serialize this element to a file, optionally disabling formatting.

Save(TextWriter) Save(TextWriter) Save(TextWriter) Save(TextWriter)

將這個項目序列化成 TextWriterSerialize this element to a TextWriter.

Save(TextWriter, SaveOptions) Save(TextWriter, SaveOptions) Save(TextWriter, SaveOptions) Save(TextWriter, SaveOptions)

將這個項目序列化成 TextWriter (可選擇是否停用格式設定)。Serialize this element to a TextWriter, optionally disabling formatting.

Save(XmlWriter) Save(XmlWriter) Save(XmlWriter) Save(XmlWriter)

將這個項目序列化成 XmlWriterSerialize this element to an XmlWriter.

SaveAsync(Stream, SaveOptions, CancellationToken) SaveAsync(Stream, SaveOptions, CancellationToken) SaveAsync(Stream, SaveOptions, CancellationToken) SaveAsync(Stream, SaveOptions, CancellationToken)

以非同步方式將這個 XElement 輸出至 StreamAsynchronously outputs this XElement to a Stream.

SaveAsync(TextWriter, SaveOptions, CancellationToken) SaveAsync(TextWriter, SaveOptions, CancellationToken) SaveAsync(TextWriter, SaveOptions, CancellationToken) SaveAsync(TextWriter, SaveOptions, CancellationToken)

以非同步方式將這個 XElement 輸出至 TextWriterAsynchronously outputs this XElement to a TextWriter.

SaveAsync(XmlWriter, CancellationToken) SaveAsync(XmlWriter, CancellationToken) SaveAsync(XmlWriter, CancellationToken) SaveAsync(XmlWriter, CancellationToken)

以非同步方式將這個 XElement 輸出至 XmlWriterAsynchronously outputs this XElement to an XmlWriter.

SetAttributeValue(XName, Object) SetAttributeValue(XName, Object) SetAttributeValue(XName, Object) SetAttributeValue(XName, Object)

設定屬性的值、加入屬性或移除屬性。Sets the value of an attribute, adds an attribute, or removes an attribute.

SetElementValue(XName, Object) SetElementValue(XName, Object) SetElementValue(XName, Object) SetElementValue(XName, Object)

設定子元素的值、加入子元素或移除子元素。Sets the value of a child element, adds a child element, or removes a child element.

SetValue(Object) SetValue(Object) SetValue(Object) SetValue(Object)

設定這個元素的值。Sets the value of this element.

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

針對這個節點傳回縮排的 XML。Returns the indented XML for this node.

(Inherited from XNode)
ToString(SaveOptions) ToString(SaveOptions) ToString(SaveOptions) ToString(SaveOptions)

傳回這個節點的 XML (可選擇是否停用格式設定)。Returns the XML for this node, optionally disabling formatting.

(Inherited from XNode)
WriteTo(XmlWriter) WriteTo(XmlWriter) WriteTo(XmlWriter) WriteTo(XmlWriter)

將這個項目寫入至 XmlWriterWrite this element to an XmlWriter.

WriteToAsync(XmlWriter, CancellationToken) WriteToAsync(XmlWriter, CancellationToken) WriteToAsync(XmlWriter, CancellationToken) WriteToAsync(XmlWriter, CancellationToken)

以非同步方式將這個 XElement 寫入至指定的寫入器。Asynchronously writes this XElement to the specified writer.

運算子

Explicit(XElement to Boolean) Explicit(XElement to Boolean) Explicit(XElement to Boolean) Explicit(XElement to Boolean)

將此 XElement 的值轉型為 BooleanCast the value of this XElement to a Boolean.

Explicit(XElement to DateTime) Explicit(XElement to DateTime) Explicit(XElement to DateTime) Explicit(XElement to DateTime)

將此 XElement 的值轉型為 DateTimeCast the value of this XElement to a DateTime.

Explicit(XElement to DateTimeOffset) Explicit(XElement to DateTimeOffset) Explicit(XElement to DateTimeOffset) Explicit(XElement to DateTimeOffset)

將此 XAttribute 的值轉型為 DateTimeOffsetCast the value of this XAttribute to a DateTimeOffset.

Explicit(XElement to Decimal) Explicit(XElement to Decimal) Explicit(XElement to Decimal) Explicit(XElement to Decimal)

將此 XElement 的值轉型為 DecimalCast the value of this XElement to a Decimal.

Explicit(XElement to Double) Explicit(XElement to Double) Explicit(XElement to Double) Explicit(XElement to Double)

將此 XElement 的值轉型為 DoubleCast the value of this XElement to a Double.

Explicit(XElement to Guid) Explicit(XElement to Guid) Explicit(XElement to Guid) Explicit(XElement to Guid)

將此 XElement 的值轉型為 GuidCast the value of this XElement to a Guid.

Explicit(XElement to Int32) Explicit(XElement to Int32) Explicit(XElement to Int32) Explicit(XElement to Int32)

將此 XElement 的值轉型為 Int32Cast the value of this XElement to an Int32.

Explicit(XElement to Int64) Explicit(XElement to Int64) Explicit(XElement to Int64) Explicit(XElement to Int64)

將此 XElement 的值轉型為 Int64Cast the value of this XElement to an Int64.

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

將此 XElement 的值轉型為 Nullable<T>BooleanCast the value of this XElement to a Nullable<T> of Boolean.

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

將此 XElement 的值轉型為 Nullable<T>DateTimeCast the value of this XElement to a Nullable<T> of DateTime.

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

將此 XElement 的值轉型為 Nullable<T>DateTimeOffsetCast the value of this XElement to a Nullable<T> of DateTimeOffset.

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

將此 XElement 的值轉型為 Nullable<T>DecimalCast the value of this XElement to a Nullable<T> of Decimal.

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

將此 XElement 的值轉型為 Nullable<T>DoubleCast the value of this XElement to a Nullable<T> of Double.

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

將此 XElement 的值轉型為 Nullable<T>GuidCast the value of this XElement to a Nullable<T> of Guid.

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

將此 XElement 的值轉型為 Nullable<T>Int32Cast the value of this XElement to a Nullable<T> of Int32.

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

將此 XElement 的值轉型為 Nullable<T>Int64Cast the value of this XElement to a Nullable<T> of Int64.

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

將此 XElement 的值轉型為 Nullable<T>SingleCast the value of this XElement to a Nullable<T> of Single.

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

將此 XElement 的值轉型為 Nullable<T>TimeSpanCast the value of this XElement to a Nullable<T> of TimeSpan.

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

將此 XElement 的值轉型為 Nullable<T>UInt32Cast the value of this XElement to a Nullable<T> of UInt32.

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

將此 XElement 的值轉型為 Nullable<T>UInt64Cast the value of this XElement to a Nullable<T> of UInt64.

Explicit(XElement to Single) Explicit(XElement to Single) Explicit(XElement to Single) Explicit(XElement to Single)

將此 XElement 的值轉型為 SingleCast the value of this XElement to a Single.

Explicit(XElement to String) Explicit(XElement to String) Explicit(XElement to String) Explicit(XElement to String)

將此 XElement 的值轉型為 StringCast the value of this XElement to a String.

Explicit(XElement to TimeSpan) Explicit(XElement to TimeSpan) Explicit(XElement to TimeSpan) Explicit(XElement to TimeSpan)

將此 XElement 的值轉型為 TimeSpanCast the value of this XElement to a TimeSpan.

Explicit(XElement to UInt32) Explicit(XElement to UInt32) Explicit(XElement to UInt32) Explicit(XElement to UInt32)

將此 XElement 的值轉型為 UInt32Cast the value of this XElement to a UInt32.

Explicit(XElement to UInt64) Explicit(XElement to UInt64) Explicit(XElement to UInt64) Explicit(XElement to UInt64)

將此 XElement 的值轉型為 UInt64Cast the value of this XElement to a UInt64.

明確介面實作

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

取得值,指出此 XObject 是否具有行資訊。Gets a value indicating whether or not this XObject has line information.

(Inherited from XObject)
IXmlSerializable.GetSchema() IXmlSerializable.GetSchema() IXmlSerializable.GetSchema() IXmlSerializable.GetSchema()

取得 XML 結構描述定義,描述這個物件的 XML 表示。Gets an XML schema definition that describes the XML representation of this object.

IXmlSerializable.ReadXml(XmlReader) IXmlSerializable.ReadXml(XmlReader) IXmlSerializable.ReadXml(XmlReader) IXmlSerializable.ReadXml(XmlReader)

從物件的 XML 表示產生該物件。Generates an object from its XML representation.

IXmlSerializable.WriteXml(XmlWriter) IXmlSerializable.WriteXml(XmlWriter) IXmlSerializable.WriteXml(XmlWriter) IXmlSerializable.WriteXml(XmlWriter)

將物件轉換成其 XML 表示。Converts an object into its XML representation.

事件

Changed Changed Changed Changed

當此 XObject 或其任何子代發生變更時會引發。Raised when this XObject or any of its descendants have changed.

(Inherited from XObject)
Changing Changing Changing Changing

當此 XObject 或其任何子代發生變更時會引發。Raised when this XObject or any of its descendants are about to change.

(Inherited from XObject)

擴充方法

GetSchemaInfo(XElement) GetSchemaInfo(XElement) GetSchemaInfo(XElement) GetSchemaInfo(XElement)

取得已驗證項目的後結構描述驗證資訊集 (PSVI)。Gets the post-schema-validation infoset (PSVI) of a validated element.

Validate(XElement, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XElement, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XElement, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler) Validate(XElement, XmlSchemaObject, XmlSchemaSet, ValidationEventHandler)

這個方法會驗證 XElement 樹狀子目錄是否符合指定的 XmlSchemaObjectXmlSchemaSetThis method validates that an XElement sub-tree conforms to a specified XmlSchemaObject and an XmlSchemaSet.

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

驗證 XElement 樹狀子目錄是否符合指定的 XmlSchemaObjectXmlSchemaSet,並選擇性地將後結構描述驗證資訊集 (PSVI) 填入 XML 樹狀目錄。Validates that an XElement sub-tree conforms to a specified XmlSchemaObject and an XmlSchemaSet, optionally populating the XML tree with the post-schema-validation infoset (PSVI).

CreateNavigator(XNode) CreateNavigator(XNode) CreateNavigator(XNode) CreateNavigator(XNode)

建立 XPathNavigatorXNodeCreates an XPathNavigator for an XNode.

CreateNavigator(XNode, XmlNameTable) CreateNavigator(XNode, XmlNameTable) CreateNavigator(XNode, XmlNameTable) CreateNavigator(XNode, XmlNameTable)

建立 XPathNavigatorXNodeCreates an XPathNavigator for an XNode. XmlNameTable 可讓 XPath 運算式處理時更有效率。The XmlNameTable enables more efficient XPath expression processing.

XPathEvaluate(XNode, String) XPathEvaluate(XNode, String) XPathEvaluate(XNode, String) XPathEvaluate(XNode, String)

評估 XPath 運算式。Evaluates an XPath expression.

XPathEvaluate(XNode, String, IXmlNamespaceResolver) XPathEvaluate(XNode, String, IXmlNamespaceResolver) XPathEvaluate(XNode, String, IXmlNamespaceResolver) XPathEvaluate(XNode, String, IXmlNamespaceResolver)

評估 XPath 運算式,並使用指定的 IXmlNamespaceResolver 解析命名空間後置字元。Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String)

使用 XPath 運算式選取 XElementSelects an XElement using a XPath expression.

XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver)

使用 XPath 運算式選取 XElement,並使用指定的 IXmlNamespaceResolver 解析命名空間後置字元。Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

XPathSelectElements(XNode, String) XPathSelectElements(XNode, String) XPathSelectElements(XNode, String) XPathSelectElements(XNode, String)

使用 XPath 運算式選取項目的集合。Selects a collection of elements using an XPath expression.

XPathSelectElements(XNode, String, IXmlNamespaceResolver) XPathSelectElements(XNode, String, IXmlNamespaceResolver) XPathSelectElements(XNode, String, IXmlNamespaceResolver) XPathSelectElements(XNode, String, IXmlNamespaceResolver)

使用 XPath 運算式選取項目集合,並使用指定的 IXmlNamespaceResolver 解析命名空間後置字元。Selects a collection of elements using an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

ToXPathNavigable(XNode) ToXPathNavigable(XNode) ToXPathNavigable(XNode) ToXPathNavigable(XNode)

傳回存取子,讓您巡覽及編輯指定的 XNodeReturns an accessor that allows you to navigate and edit the specified XNode.

適用於

另請參閱