XmlDocumentFragment.OwnerDocument Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o XmlDocument lugar a que este nó pertence.
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
Valor de Propriedade
O XmlDocument que este nó pertence.
Exemplos
O exemplo seguinte adiciona um novo nó ao fragmento do documento.
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
Observações
Ao adicionar nós ao nó atual, use a XmlDocument propriedade retornada pela OwnerDocument para criar o nó.