XML Tutorials - Herong's Tutorial Examples - Version 5.02, by Dr. Herong Yang
SAX Parsing Pattern Example
This section provides a tutorial example on how to print out the SAX parsing pattern by SAXBrowser.java with a given XML file.
Now let's use another XML file, user.xml, with more elements to show the SAX parsing pattern:
<?xml version="1.0"?> <user status="active"> <!-- This is not a real user. --> <first_name>John</first_name> <last_name>Smith</last_name> </user>
Ran java SAXBrowser user.xml, I got:
Starting document... e_user a_ status=active c__ c__ c__ c__ c__ c__ e__first_name c___John c__ c__ c__ e__last_name c___Smith c__ c__ Ending document...
The program still works. But why the parser fired so many "characters()" events? It looks like the parser didn't group the space character, line feed, and cartridge return into a single char and fire one "characters()" event. It fired multiple events, one per character.
Notes and sample codes in this section are based on JDK 1.8.
Last update: 2014.
Table of Contents