Modifying a DOM Tree

We will now look at another use of the DOM API to modify the contents or structure of the XML. Unlike SAX, DOM provides a number of methods that allow nodes to be added, deleted, changed, or replaced in the DOM tree. Table 16.10 summarizes these methods.

Table 16.10. Document Interface Methods to Inspect DOM Nodes
Method Name Description
appendChild(Node newNode) Adds the new node to the end of the NodeList of children of this node.
cloneNode(boolean deep) Returns a duplicate of a node. The cloned node has no parent. If deep is true, the whole tree below this node is cloned; if false, only the node itself is cloned.
insertBefore(Node newNode, Inserts the newNode before Node refNode)the existing refNode.
removeChild(Node oldNode) ...

Get Sams Teach Yourself J2EE™ in 21 Days 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.