XmlDocument.CreateDocumentFragment Method ()

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

Public Overridable Function CreateDocumentFragment As XmlDocumentFragment

Return Value

Type: System.Xml.XmlDocumentFragment

The new XmlDocumentFragment.

DocumentFragment nodes cannot be inserted into a document. However, you can insert children of the DocumentFragment node into a document.

The following example adds new nodes to an XML document.

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

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: