Bulk Insertion Using Document Fragment

The DocumentFragment node is a very lightweight version of the Element object meant for DOM cut and paste operations. A DocumentFragment node is a generic container for other nodes that can be inserted as a group somewhere else in the hierarchy. The DocumentFragment node must implement the DocumentFragment interface, which is a marker interface that extends Node but adds no new methods. The key to the DocumentFragment node type is how other methods treat it when it is passed as a parameter. Consider the following Java code:

 import org.w3c.dom.*; void dupEm(Document doc) { DocumentFragment frag = doc.createDocumentFragment(); NodeList authors = doc.getElementsByTagNameNS("urn:bru", "author"); frag.appendChild(authors.item(0)); ...

Get Essential XML: Beyond Markup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.