XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / DocumentFragment

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

The DocumentFragment provides a border, in which fragments of the XML document can be stored temporarily. Since this interface defines no methods or attributes of its own, it has only those supplied by the Node interface. One or more balanced XML trees can be placed in the fragment.

A typical use of a document fragment is cutting and pasting in an XML editor. The user can select one or more subtrees and move or copy them into the fragment:

<dokument>
    <elter>
        <kind_1></kind_1>
        <kind_2></kind_2>
    </elter>
    <elter>
    </elter>
</dokument>

Suppose the user copies the two child nodes to the clipboard. In this case, a DOM application would do the following:

When the user wants to paste the copied nodes elsewhere, the DocumentFragment is passed to the appendChild() method of the target node. However, only the children of the DocumentFragment node are actually appended; the fragment node itself is ignored.

Java example

// Erzeuge ein DocumentFragment-Objekt.
DocumentFragment dfNorm = doc.createDocumentFragment(  );

  

 

 

 

back to top