Java Reference
In-Depth Information
large XML documents.) And with SAX, you can't really “navigate” a document because you
have only a stream of events, not a real structure. For that, you want DOM or JDOM.
Parsing XML with DOM
Problem
You want to examine an XML file in detail.
Solution
Use DOM to parse the document and process the resulting in-memory tree.
Discussion
The Document Object Model (DOM) is a tree-structured representation of the information in
an XML document. It consists of several interfaces, the most important of which is the node .
All are in the package org.w3c.dom , reflecting the influence of the World Wide Web Con-
sortium in creating and promulgating the DOM. The major DOM interfaces are shown in
Table 20-1 .
Table 20-1. Major DOM interfaces
Interface Function
Document Top-level representation of an XML document
Node
Representation of any node in the XML tree
Element
An XML element
Text
A textual string
You don't have to implement these interfaces; the parser generates them. When you start cre-
ating or modifying XML documents in Generating Your Own XML with DOM and the XML
Transformer , you can create nodes. But even then there are implementing classes. Parsing an
XML document with DOM is syntactically similar to processing a file with XSL; that is, you
Search WWH ::




Custom Search