XDocument クラス
定義
XML ドキュメントを表します。Represents an XML document. XDocument オブジェクトのコンポーネントと使用方法については、「XDocument クラスの概要」をご覧ください。For the components and usage of an XDocument object, see XDocument Class Overview.
public ref class XDocument : System::Xml::Linq::XContainer
public class XDocument : System.Xml.Linq.XContainer
type XDocument = class
inherit XContainer
Public Class XDocument
Inherits XContainer
- 継承
例
次の例では、ドキュメントを作成し、コメントと要素を追加します。The following example creates a document, and then adds a comment and an element to it. 次に、クエリの結果を使用して別のドキュメントを合成します。It then composes another document using the results of a query.
XDocument srcTree = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
new XElement("Child1", "data1"),
new XElement("Child2", "data2"),
new XElement("Child3", "data3"),
new XElement("Child2", "data4"),
new XElement("Info5", "info5"),
new XElement("Info6", "info6"),
new XElement("Info7", "info7"),
new XElement("Info8", "info8")
)
);
XDocument doc = new XDocument(
new XComment("This is a comment"),
new XElement("Root",
from el in srcTree.Element("Root").Elements()
where ((string)el).StartsWith("data")
select el
)
);
Console.WriteLine(doc);
Dim srcTree As XDocument = _
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--This is a comment-->
<Root>
<Child1>data1</Child1>
<Child2>data2</Child2>
<Child3>data3</Child3>
<Child2>data4</Child2>
<Info5>info5</Info5>
<Info6>info6</Info6>
<Info7>info7</Info7>
<Info8>info8</Info8>
</Root>
Dim doc As XDocument = _
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--This is a comment-->
<Root>
<%= From el In srcTree.<Root>.Elements _
Where CStr(el).StartsWith("data") _
Select el %>
</Root>
Console.WriteLine(doc)
この例を実行すると、次の出力が生成されます。This example produces the following output:
<!--This is a comment-->
<Root>
<Child1>data1</Child1>
<Child2>data2</Child2>
<Child3>data3</Child3>
<Child2>data4</Child2>
</Root>
注釈
の有効なコンテンツの詳細についXDocumentては、「 XElement オブジェクトと XDocument オブジェクトの有効なコンテンツ」を参照してください。For details about the valid content of an XDocument, see Valid Content of XElement and XDocument Objects.
コンストラクター
XDocument() |
XDocument クラスの新しいインスタンスを初期化します。Initializes a new instance of the XDocument class. |
XDocument(Object[]) |
指定した内容で、XDocument クラスの新しいインスタンスを初期化します。Initializes a new instance of the XDocument class with the specified content. |
XDocument(XDeclaration, Object[]) |
指定した XDeclaration および内容を使用して、XDocument クラスの新しいインスタンスを初期化します。Initializes a new instance of the XDocument class with the specified XDeclaration and content. |
XDocument(XDocument) |
既存の XDocument オブジェクトから XDocument クラスの新しいインスタンスを初期化します。Initializes a new instance of the XDocument class from an existing XDocument object. |
プロパティ
BaseUri |
この XObject のベース URI を取得します。Gets the base URI for this XObject. (継承元 XObject) |
Declaration |
このドキュメントの XML 宣言を取得または設定します。Gets or sets the XML declaration for this document. |
Document |
この XDocument の XObject を取得します。Gets the XDocument for this XObject. (継承元 XObject) |
DocumentType |
このドキュメントのドキュメント型定義 (DTD: Document Type Definition) の名前を取得します。Gets the Document Type Definition (DTD) for this document. |
FirstNode |
このノードの最初の子ノードを取得します。Gets the first child node of this node. (継承元 XContainer) |
LastNode |
このノードの最後の子ノードを取得します。Gets the last child node of this node. (継承元 XContainer) |
NextNode |
このノードの次の兄弟ノードを取得します。Gets the next sibling node of this node. (継承元 XNode) |
NodeType |
このノードのノード型を取得します。Gets the node type for this node. |
Parent |
この XElement の親 XObject を取得します。Gets the parent XElement of this XObject. (継承元 XObject) |
PreviousNode |
このノードの前の兄弟ノードを取得します。Gets the previous sibling node of this node. (継承元 XNode) |
Root |
このドキュメントの XML ツリーのルート要素を取得します。Gets the root element of the XML Tree for this document. |
メソッド
Add(Object) |
指定した内容をこの XContainer の子として追加します。Adds the specified content as children of this XContainer. (継承元 XContainer) |
Add(Object[]) |
指定した内容をこの XContainer の子として追加します。Adds the specified content as children of this XContainer. (継承元 XContainer) |
AddAfterSelf(Object) |
このノードの直後に指定された内容を追加します。Adds the specified content immediately after this node. (継承元 XNode) |
AddAfterSelf(Object[]) |
このノードの直後に指定された内容を追加します。Adds the specified content immediately after this node. (継承元 XNode) |
AddAnnotation(Object) |
この XObject の注釈の一覧にオブジェクトを追加します。Adds an object to the annotation list of this XObject. (継承元 XObject) |
AddBeforeSelf(Object) |
指定した内容をこのノードの直前に追加します。Adds the specified content immediately before this node. (継承元 XNode) |
AddBeforeSelf(Object[]) |
指定した内容をこのノードの直前に追加します。Adds the specified content immediately before this node. (継承元 XNode) |
AddFirst(Object) |
指定した内容をこのドキュメントまたは要素の最初の子として追加します。Adds the specified content as the first children of this document or element. (継承元 XContainer) |
AddFirst(Object[]) |
指定した内容をこのドキュメントまたは要素の最初の子として追加します。Adds the specified content as the first children of this document or element. (継承元 XContainer) |
Ancestors() |
このノードの先祖要素のコレクションを返します。Returns a collection of the ancestor elements of this node. (継承元 XNode) |
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. (継承元 XNode) |
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) |
CreateReader() |
このノードの XmlReader を作成します。Creates an XmlReader for this node. (継承元 XNode) |
CreateReader(ReaderOptions) |
|
CreateWriter() |
XmlWriter にノードを追加するために使用できる XContainer を作成します。Creates an XmlWriter that can be used to add nodes to the XContainer. (継承元 XContainer) |
DescendantNodes() |
このドキュメントまたは要素の子孫ノードのコレクションをドキュメント順に返します。Returns a collection of the descendant nodes for this document or element, in document order. (継承元 XContainer) |
Descendants() |
このドキュメントまたは要素の子孫要素のコレクションをドキュメント順に返します。Returns a collection of the descendant elements for this document or element, in document order. (継承元 XContainer) |
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. (継承元 XContainer) |
Element(XName) |
指定した XName の最初の子要素を (ドキュメント順に) 取得します。Gets the first (in document order) child element with the specified XName. (継承元 XContainer) |
Elements() |
この要素またはドキュメントの子要素のコレクションをドキュメント順に返します。Returns a collection of the child elements of this element or document, in document order. (継承元 XContainer) |
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. (継承元 XContainer) |
ElementsAfterSelf() |
このノードの後にある兄弟要素のコレクションをドキュメント順に返します。Returns a collection of the sibling elements after this node, in document order. (継承元 XNode) |
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. (継承元 XNode) |
ElementsBeforeSelf() |
このノードの前にある兄弟要素のコレクションをドキュメント順に返します。Returns a collection of the sibling elements before this node, in document order. (継承元 XNode) |
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. (継承元 XNode) |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判定します。Determines whether the specified object is equal to the current object. (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。Serves as the default hash function. (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。Gets the Type of the current instance. (継承元 Object) |
IsAfter(XNode) |
ドキュメント順に基づいて、現在のノードを指定したノードの後に表示するかどうかを決定します。Determines if the current node appears after a specified node in terms of document order. (継承元 XNode) |
IsBefore(XNode) |
ドキュメント順に基づいて、現在のノードを指定したノードの前に表示するかどうかを決定します。Determines if the current node appears before a specified node in terms of document order. (継承元 XNode) |
Load(Stream) |
指定されたストリームを使用して新しい XDocument インスタンスを作成します。Creates a new XDocument instance by using the specified stream. |
Load(Stream, LoadOptions) |
指定されたストリームを使用して新しい XDocument インスタンスを作成し、必要に応じて、空白の維持、ベース URI の設定、および行情報の保持を行います。Creates a new XDocument instance by using the specified stream, optionally preserving white space, setting the base URI, and retaining line information. |
Load(String) |
ファイルから新しい XDocument を作成します。Creates a new XDocument from a file. |
Load(String, LoadOptions) |
ファイルから新しい XDocument を作成し、必要に応じて、空白の維持、ベース URI の設定、および行情報の保持を行います。Creates a new XDocument from a file, optionally preserving white space, setting the base URI, and retaining line information. |
Load(TextReader) |
XDocument から新しい TextReader を作成します。Creates a new XDocument from a TextReader. |
Load(TextReader, LoadOptions) |
TextReader から新しい XDocument を作成し、必要に応じて、空白の維持、ベース URI の設定、および行情報の保持を行います。Creates a new XDocument from a TextReader, optionally preserving white space, setting the base URI, and retaining line information. |
Load(XmlReader) |
XmlReader から新しいXDocument を作成します。Creates a new XDocument from an XmlReader. |
Load(XmlReader, LoadOptions) |
XmlReader から XDocument を読み込み、必要に応じて、ベース URI の設定および行情報の保持を行います。Loads an XDocument from an XmlReader, optionally setting the base URI, and retaining line information. |
LoadAsync(Stream, LoadOptions, CancellationToken) |
新しい XDocument を非同期に作成し、指定したストリームからその基になる XML ツリーを初期化します。必要に応じて、空白を維持します。Asynchronously creates a new XDocument and initializes its underlying XML tree from the specified stream, optionally preserving white space. |
LoadAsync(TextReader, LoadOptions, CancellationToken) |
新しい XDocument を作成し、指定した TextReader パラメーターを使用してその基になる XML ツリーを初期化します。必要に応じて、空白を維持します。Creates a new XDocument and initializes its underlying XML tree using the specified TextReader parameter, optionally preserving white space. |
LoadAsync(XmlReader, LoadOptions, CancellationToken) |
指定した XmlReader の内容を含む新しい XDocument を作成します。Creates a new XDocument containing the contents of the specified XmlReader. |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
Nodes() |
この要素またはドキュメントの子ノードのコレクションをドキュメント順に返します。Returns a collection of the child nodes of this element or document, in document order. (継承元 XContainer) |
NodesAfterSelf() |
このノードの後にある兄弟ノードのコレクションをドキュメント順に返します。Returns a collection of the sibling nodes after this node, in document order. (継承元 XNode) |
NodesBeforeSelf() |
このノードの前にある兄弟ノードのコレクションをドキュメント順に返します。Returns a collection of the sibling nodes before this node, in document order. (継承元 XNode) |
Parse(String) |
文字列から新しい XDocument を作成します。Creates a new XDocument from a string. |
Parse(String, LoadOptions) |
文字列から新しい XDocument を作成し、必要に応じて、空白の維持、ベース URI の設定、および行情報の保持を行います。Creates a new XDocument from a string, optionally preserving white space, setting the base URI, and retaining line information. |
Remove() |
現在のノードを親から削除します。Removes this node from its parent. (継承元 XNode) |
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) |
RemoveNodes() |
このドキュメントまたは要素から子ノードを削除します。Removes the child nodes from this document or element. (継承元 XContainer) |
ReplaceNodes(Object) |
このドキュメントまたは要素の子ノードを指定された内容で置き換えます。Replaces the children nodes of this document or element with the specified content. (継承元 XContainer) |
ReplaceNodes(Object[]) |
このドキュメントまたは要素の子ノードを指定された内容で置き換えます。Replaces the children nodes of this document or element with the specified content. (継承元 XContainer) |
ReplaceWith(Object) |
現在のノードを指定された内容に置き換えます。Replaces this node with the specified content. (継承元 XNode) |
ReplaceWith(Object[]) |
現在のノードを指定された内容に置き換えます。Replaces this node with the specified content. (継承元 XNode) |
Save(Stream) |
この XDocument を指定した Stream に出力します。Outputs this XDocument to the specified Stream. |
Save(Stream, SaveOptions) |
オプションで書式設定動作を指定して、指定した Stream にこの XDocument を出力します。Outputs this XDocument to the specified Stream, optionally specifying formatting behavior. |
Save(String) |
この XDocument をシリアル化してファイルに書き込み、既存のファイルを上書きします (存在する場合)。Serialize this XDocument to a file, overwriting an existing file, if it exists. |
Save(String, SaveOptions) |
この XDocument をシリアル化してファイルに書き込み、必要に応じて、書式設定を無効にします。Serialize this XDocument to a file, optionally disabling formatting. |
Save(TextWriter) |
この XDocument をシリアル化して TextWriter に書き込みます。Serialize this XDocument to a TextWriter. |
Save(TextWriter, SaveOptions) |
この XDocument をシリアル化して TextWriter に書き込み、必要に応じて、書式設定を無効にします。Serialize this XDocument to a TextWriter, optionally disabling formatting. |
Save(XmlWriter) |
この XDocument をシリアル化して XmlWriter に書き込みます。Serialize this XDocument to an XmlWriter. |
SaveAsync(Stream, SaveOptions, CancellationToken) |
この XDocument を Stream に出力します。Output this XDocument to a Stream. |
SaveAsync(TextWriter, SaveOptions, CancellationToken) |
この XDocument を TextWriter に書き込みます。Writes this XDocument to a TextWriter. |
SaveAsync(XmlWriter, CancellationToken) |
この XDocument を XmlWriter に書き込みます。Writes this XDocument to an XmlWriter. |
ToString() |
このノードに対してインデントが設定された XML を返します。Returns the indented XML for this node. (継承元 XNode) |
ToString(SaveOptions) |
このノードに対して XML を返し、オプションで書式設定を無効にします。Returns the XML for this node, optionally disabling formatting. (継承元 XNode) |
WriteTo(XmlWriter) |
このドキュメントを XmlWriter に書き込みます。Write this document to an XmlWriter. |
WriteToAsync(XmlWriter, CancellationToken) |
この XDocument の基になる XML ツリーを指定した XmlWriter に書き込みます。Writes this XDocument's underlying XML tree to the specified XmlWriter. |
イベント
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) |
拡張メソッド
Validate(XDocument, XmlSchemaSet, ValidationEventHandler) |
このメソッドは、XDocument が XmlSchemaSet の XSD に準拠しているかどうかを検証します。This method validates that an XDocument conforms to an XSD in an XmlSchemaSet. |
Validate(XDocument, XmlSchemaSet, ValidationEventHandler, Boolean) |
XDocument が XmlSchemaSet の XSD に準拠しているかどうかを検証します。オプションで、スキーマ検証後の infoset (PSVI) を XML ツリーに設定できます。Validates that an XDocument conforms to an XSD in an XmlSchemaSet, optionally populating the XML tree with the post-schema-validation infoset (PSVI). |
CreateNavigator(XNode) |
XPathNavigator の XNode を作成します。Creates an XPathNavigator for an XNode. |
CreateNavigator(XNode, XmlNameTable) |
XPathNavigator の XNode を作成します。Creates an XPathNavigator for an XNode. XmlNameTable を使用すると、XPath 式をより効率的に処理できます。The XmlNameTable enables more efficient XPath expression processing. |
XPathEvaluate(XNode, String) |
XPath 式を評価します。Evaluates an XPath expression. |
XPathEvaluate(XNode, String, IXmlNamespaceResolver) |
XPath 式を評価します。このとき、指定された IXmlNamespaceResolver を使用して名前空間プレフィックスを解決します。Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver. |
XPathSelectElement(XNode, String) |
XPath 式を使用して XElement を選択します。Selects an XElement using a XPath expression. |
XPathSelectElement(XNode, String, IXmlNamespaceResolver) |
XPath 式を使用して XElement を選択します。このとき、指定された IXmlNamespaceResolver を使用して名前空間プレフィックスを解決します。Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver. |
XPathSelectElements(XNode, String) |
XPath 式を使用して要素のコレクションを選択します。Selects a collection of elements using an XPath expression. |
XPathSelectElements(XNode, String, IXmlNamespaceResolver) |
XPath 式を使用して要素のコレクションを選択します。このとき、指定された IXmlNamespaceResolver を使用して名前空間プレフィックスを解決します。Selects a collection of elements using an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver. |
ToXPathNavigable(XNode) |
指定した XNode に移動して編集できるアクセサーを返します。Returns an accessor that allows you to navigate and edit the specified XNode. |