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; ...

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.