Creating DOM Elements
One area we have not examined closely is how to create and insert objects into a DOM tree. There are two methods for doing this. The first is to build an item from scratch and then insert it. The second it to use the Clone method to clone a given element and then the setNodeValue method to manipulate its contents before inserting it into the tree. The second approach is left as an exercise for the reader. Let's examine how we build an element from scratch.
Adding information to a DOM tree is simple enough if we remember that DOM documents are hierarchical. Looking back to our original catalog example, we remember that a catalog contained "entry" items, each containing a number of subelements. So we can create a new entry ...
Get XML Development with Java™ 2 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.