- Creating Applications with Java API for XML Parsing (JAXP)
- Understanding XML
- XML Related Tools
- Creating an XML Document
- Creating a Document Type Definition (DTD)
- Parsing with the Simple API for XML (SAX)
- Parsing with the Document Object Model (DOM)
- An XML Version of the CruiseList Application
In this chapter we looked at how to use JAXP to process XML, one of the most exciting technologies in the computing world today. XML's combination of standardized processing on custom data is a powerful approach.
Early in the chapter, you learned how to parse an XML document and extract its information. We used the JAXP SAX approach to process the data sequentially. This approach has the advantage of performing better when large XML documents are parsed. The fact that only part of the document is contained in memory at any time during processing makes its memory requirements more manageable.
Then you learned how to parse the XML document using the JAXP's DOM approach. The DOM approach creates a treelike structure in memory that represents the document. Method calls and recursion are then used to traverse the tree and extract the data. This approach is nice in that the creation of the tree is automatic. Traversing it using recursion is a very comfortable approach for many programmers. In addition, the tree can be updated and written out, creating a database-like effect. The drawback to the DOM approach is the resource requirements of having the whole tree in virtual memory at the same time. For this reason, we can sometimes achieve better performance using SAX rather than DOM.
Finally, we created a real-world application that demonstrated how JAXP and XML could be used to facilitate distributed processing. We created an object in one application and translated it into an XML document. Another application opened the document, parsed it, and re-created the same object in its own JVM.