このノードが属する XmlDocument を取得します。
Overrides Public ReadOnly Property OwnerDocument As XmlDocument
[C#]
public override XmlDocument OwnerDocument {get;}
[C++]
public: __property XmlDocument* get_OwnerDocument();
[JScript]
public override function get OwnerDocument() : XmlDocument;
プロパティ値
このノードが属する XmlDocument 。
解説
ノードを現在のノードに追加する場合は、 OwnerDocument プロパティによって返された XmlDocument を使用してノードを作成します。
使用例
[Visual Basic, C#, C++] 新しいノードをドキュメントのフラグメントに追加する例を次に示します。
Option Explicit
Option Strict
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
' Create the XmlDocument.
Dim doc As New XmlDocument()
doc.LoadXml("<items/>")
' Create a document fragment.
Dim docFrag As XmlDocumentFragment = doc.CreateDocumentFragment()
' Display the owner document of the document fragment.
Console.WriteLine(docFrag.OwnerDocument.OuterXml)
' Add nodes to the document fragment. Notice that the
' new element is created using the owner document of
' the document fragment.
Dim elem As XmlElement = doc.CreateElement("item")
elem.InnerText = "widget"
docFrag.AppendChild(elem)
Console.WriteLine("Display the document fragment...")
Console.WriteLine(docFrag.OuterXml)
End Sub 'Main
End Class 'Sample
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<items/>");
// Create a document fragment.
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
// Display the owner document of the document fragment.
Console.WriteLine(docFrag.OwnerDocument.OuterXml);
// Add nodes to the document fragment. Notice that the
// new element is created using the owner document of
// the document fragment.
XmlElement elem = doc.CreateElement("item");
elem.InnerText = "widget";
docFrag.AppendChild(elem);
Console.WriteLine("Display the document fragment...");
Console.WriteLine(docFrag.OuterXml);
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
// Create the XmlDocument.
XmlDocument* doc = new XmlDocument();
doc->LoadXml(S"<items/>");
// Create a document fragment.
XmlDocumentFragment* docFrag = doc->CreateDocumentFragment();
// Display the owner document of the document fragment.
Console::WriteLine(docFrag->OwnerDocument->OuterXml);
// Add nodes to the document fragment. Notice that the
// new element is created using the owner document of
// the document fragment.
XmlElement* elem = doc->CreateElement(S"item");
elem->InnerText = S"widget";
docFrag->AppendChild(elem);
Console::WriteLine(S"Display the document fragment...");
Console::WriteLine(docFrag->OuterXml);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
XmlDocumentFragment クラス | XmlDocumentFragment メンバ | System.Xml 名前空間