O'Reilly logo

XML and Java™ from scratch by Nicholas Chase

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required