Programming with DOM
In this first DOM example, an XML document will be parsed into a DOM representation. Then the code will iterate through the nodes of the tree structure and output information regarding each node. This iterating method will be embedded within the JSP page to make it easy to alter in this chapter.
NOTE
Our examples serialize DOMs to the output. These examples are only intended to demonstrate the workings of DOM in Java. If you need a production-grade serializer, check out the XMLSerializer class found in the Xerces parser.
The complete JSP page is shown in Listing 5.2 and should be saved as webapps\xmlbook\chapter5\DOMExample.jsp.
Listing 5.2. DOMExample.jsp
<%@ page import="org.w3c.dom.*, org.apache.xerces.parsers.DOMParser" ... |
Get JSP™ and XML Integrating XML and Web Services in Your JSP™ Application 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.