Freigeben über


XmlDocument.CreateDocumentFragment-Methode

Erstellt ein XmlDocumentFragment.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Overridable Function CreateDocumentFragment As XmlDocumentFragment
'Usage
Dim instance As XmlDocument
Dim returnValue As XmlDocumentFragment

returnValue = instance.CreateDocumentFragment
public virtual XmlDocumentFragment CreateDocumentFragment ()
public:
virtual XmlDocumentFragment^ CreateDocumentFragment ()
public XmlDocumentFragment CreateDocumentFragment ()
public function CreateDocumentFragment () : XmlDocumentFragment

Rückgabewert

Das neue XmlDocumentFragment.

Hinweise

DocumentFragment-Knoten können nicht in ein Dokument eingefügt werden. Sie können jedoch untergeordnete Elemente eines DocumentFragment-Knotens in ein Dokument einfügen.

Beispiel

Im folgenden Beispiel werden einem XML-Dokument neue Knoten hinzugefügt.

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()
        
        'Set the contents of the document fragment.
        docFrag.InnerXml = "<item>widget</item>"
        
        'Add the children of the document fragment to the
        'original document.
        doc.DocumentElement.AppendChild(docFrag)
        
        Console.WriteLine("Display the modified XML...")
        Console.WriteLine(doc.OuterXml)
    End Sub 'Main 
End Class 'Sample
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();
 
    //Set the contents of the document fragment.
    docFrag.InnerXml ="<item>widget</item>";

   //Add the children of the document fragment to the
   //original document.
   doc.DocumentElement.AppendChild(docFrag);

   Console.WriteLine("Display the modified XML...");
   Console.WriteLine(doc.OuterXml);
  
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<items/>" );
   
   //Create a document fragment.
   XmlDocumentFragment^ docFrag = doc->CreateDocumentFragment();
   
   //Set the contents of the document fragment.
   docFrag->InnerXml = "<item>widget</item>";
   
   //Add the children of the document fragment to the
   //original document.
   doc->DocumentElement->AppendChild( docFrag );
   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->OuterXml );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        //Create the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<items/>");

        //Create a document fragment.
        XmlDocumentFragment docFrag = doc.CreateDocumentFragment();

        //Set the contents of the document fragment.
        docFrag.set_InnerXml("<item>widget</item>");

        //Add the children of the document fragment to the
        //original document.
        doc.get_DocumentElement().AppendChild(docFrag);

        Console.WriteLine("Display the modified XML...");
        Console.WriteLine(doc.get_OuterXml());
    } //main
} //Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlDocument-Klasse
XmlDocument-Member
System.Xml-Namespace