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:
A
DocumentFragmentobject is created.Use the methods
cloneNode( )andappendChild( )to place the two child nodes in the new object.
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( );
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top