Writing a DOM Parser
There's no question that it's easier to write DOM-based code because you can access the entire document structure as a memory object rather than having to collect information as it passes by during a serial parse of the document. You can use the same DTD and XML, but the parser is totally different when written as a DOM implementation, as you can see in Listing 14.6.
Listing 14.6. DOMProductImporter.java
package com.bfg.xml; import org.apache.xerces.dom.TextImpl; import org.xml.sax.SAXParseException; import org.apache.xerces.parsers.DOMParser; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import java.sql.*; ... |
Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL 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.