|
|
Now that you have your XML file, how do you read it? Open a FileInputStream?
Nah, it's not nearly that complicated. As long as we write our XML
in good form, we can use parsers that come with java. The
parser's job is to:
-
reads the file
-
verifies the format of the file
-
inteprets elements from the file
-
allows the programmer to access those elements.
-
The parsers that come with Java include:
-
DOM, the Document Object Model, which reads XML documents into a tree.
This is slightly easier than SAX.
-
SAX, the Simple API for XML, which generates events when it reads an XML
document. SAX is ideal when you only want to know part of an XML
document, or when the XML document is long.
-
JDOM (not mentioned in the book) is
an alternative that integrates well with SAX and DOM.
Reading an XML file
|