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

Our First DOM: Stepping Through Our XML

It's great that we can set a parameter for the style sheet, but if we have to run each product page separately, what have we gained? It would certainly be more convenient if we could find a way to run all our pages at once. What we need to do is find a way to create a product page for every product in our XML file.

Fortunately, we can use Java to step through our XML and process the style sheet for each product_id it finds.

The first thing we need to do is parse the document and find out just how many product_ids there are, as in Listing 4.20.

Listing 4.20. TransformProd.java: Parsing the Document
 0 :import javax.xml.transform.TransformerFactory; 1 :import javax.xml.transform.Transformer; 2 :import javax.xml.transform.stream.StreamSource; ...

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