XmlDocumentFragment.OwnerDocument Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan tempat XmlDocument simpul ini berada.
public:
virtual property System::Xml::XmlDocument ^ OwnerDocument { System::Xml::XmlDocument ^ get(); };
public override System.Xml.XmlDocument OwnerDocument { get; }
member this.OwnerDocument : System.Xml.XmlDocument
Public Overrides ReadOnly Property OwnerDocument As XmlDocument
Nilai Properti
Tempat XmlDocument simpul ini berada.
Contoh
Contoh berikut menambahkan simpul baru ke fragmen dokumen.
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);
}
}
Option Explicit
Option Strict
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
End Class
Keterangan
Saat menambahkan simpul ke simpul saat ini, gunakan yang XmlDocument dikembalikan oleh OwnerDocument properti untuk membuat simpul.