Adding Nodes to a Document

Now that we know we're accessing all the information in our document, it's time to start adding it to the new document. To do that, we need to make changes to our processNode() method. But what sort of changes? Let's think about what we want to do each time the method processes a node.

Aside from just printing out its progress, for each node of the old document, we must create a new node with the same information. To do that, we need a Document object, to enable us to have access to the creation methods we talked about earlier. We also will need to know which node to add this new node to!

In Listing 6.7, we start by adding these new nodes to processNode().

Listing 6.7. ReviewOrder.java: Adding Nodes to a Document

Get XML and Java™ from scratch 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.