|
|
The DOM parser builds a tree representing the XML file and stores it in
memory. SAX is a different model - it does not store the XML in a
tree, but rather generate events as it comes upon XML tags and text.
-
To use SAX, you need to create a class that implements ContentHandler
and provides implementation for its methods.
-
Or, extend DefaultHanlder,
which implements four interfaces and provides do-nothing handlers for them.
Then you only provide implementation for the events you wish to handle.
-
For example, if you want to take some action when the drivername element
is reached, you'll want to override the startElement method to
search for this tag.
-
SAX is great for large XML files. It's also nice if you just want
to get one piece of information out of an XML file without reading the
entire file into memory.
-
But DOM is fine for smaller scale applications. So, while it's good
to know that SAX exists, and how it works, we'll stick with DOM for our
applications.
|