Java Reference
In-Depth Information
Document Object Model (DOM): This is the most convenient interface. When
you use this interface, the entire XML document is loaded into memory, and
the elements in the document are loaded into a hierarchy of individual objects.
Your program may then navigate through the hierarchy to read or write the ob-
ject that represents the XML tag you are interested in.
This interface is the most straightforward and the most intuitive. It is a
quite powerful mechanism to navigate complex XML documents. However,
this convenience comes at a cost. Since the entire XML document resides in
memory, it is very slow and very memory intensive.
Simple API for XML parsing (SAX): This interface is much faster and uses less
memory than the DOM interface. XML tags are read or written in sections as a
stream of bytes. As an XML tag is identified in the stream, the SAX parser in-
vokes callbacks , or predefined methods in your program. In these methods,
you can collect and store the XML content that you are interested in.
This method, while faster and more scalable, does have its own costs in the
form of increased programming complexity. You more or less have to write
low-level custom code for each XML tag that you need to process. And in
many cases, you still need to process the entire document.
Streaming API for XML (StAX): This latest interface combines some of the
simplicity of the DOM with the speed of the SAX interface. When using this in-
terface, your program gets an iterator and requests sections of the XML docu-
ment. You can then decide to process that information, skip to the next section,
or just decide to stop processing. Unlike SAX, where the parser controls your
program, with StAX, your program is in control of the parser.
In many situations, you will probably find that the DOM parser is most ap-
propriate for modest-sized XML documents whose elements must be read or up-
dated randomly many times. A configuration file is a good example of this type of
access. For larger XML files that are processed most often in sequential order, the
StAX interface is superior. A batch interface from an external system is a good ex-
ample this type of XML document.
XML AND HTML
Unlike HTML, XML does not define presentation attributes such as </font> . An
XML document designer is free to define and use such tags, but they do not cur-
rently have a generally understood meaning.
The XHTML standard combines the structure of XML with the graphical rep-
resentation capabilities of HTML. XHTML is a language definition very similar to
HTML, but it has more rigorous rules. For example, XHTML tags and attributes in
Search WWH ::




Custom Search