Java Reference
In-Depth Information
XML
Returned to your Program
<?xml version="1.0"?>
<circle>
<radius>
15
</radius>
<position>
<x-coordinate>
30
</x-coordinate>
<y-coordinate>
50
</y-coordinate>
</position>
</circle>
circle
radius
position
radius
15
y-coordinate
x-coordinate
30
50
Document Object
DOM Processing of XML
Once you have the Document object available you can call the object's methods to navigate through
the elements in the document tree starting with the root element. With DOM, the entire document is
available to you for you to process as often and in as many ways as you want. This is a major advantage
over SAX processing. The downside to this is the amount of memory occupied by the document - there
is no choice, you get it all no matter how big it is. With some documents the amount of memory
required may be prohibitively large.
DOM has one other unique advantage over SAX. It allows you to modify existing documents or create
new ones. If you want to create an XML document programmatically and then transfer it to an external
destination such as a file or another computer, DOM is the API for this since SAX has no direct
provision for creating or modifying XML documents. We will go into detail on how we can use a DOM
parser in the next chapter.
Accessing Parsers
The javax.xml.parsers package defines four classes supporting the processing of XML documents:
SAXParserFactory
Enables you to create a configurable factory object that you
can use to create a SAXParser object encapsulating a SAX-
based parser.
Defines an object that wraps a SAX-based parser.
SAXParser
DocumentBuilderFactory
Enables you to create a configurable factory object that you
can use to create a DocumentBuilder object
encapsulating a DOM-based parser.
DocumentBuilder
Defines an object that wraps a DOM-based parser.
Search WWH ::




Custom Search