The JSR-172 XML parsing package is very small. It contains the minimal
classes contained in the JAXP packages org.xml.sax
and javax.xml.parsers
.
Applications whishing to parse XML just need to get a reference to SAXParser
via SAXParserFactory
as
shown in the example below:
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
And then proceed to do the actual parsing:
InputStream in = Connection.openInputStream("..."); DefaultHandler handler = new MyDefaultHandler(); parser.parse(is, handler);
In SAX 2.0 the parsing is done using an event model. As the parser proceeds
down the XML tree, the different methods in DefaultHandler
will
be called whenever an element is found. The application is expected to process
the events it is interested in and use the data as needed.