Parsing XML with SAX

XMLReader parser =
											XMLReaderFactory.createXMLReader(
											"org.apache.xerces.parsers.SAXParser");
											parser.setContentHandler(new MyXMLHandler( ));
											parser.parse("document.xml");

The SAX API works by scanning through an XML document from start to finish and providing callbacks for events that occur within the XML document. The events include things such as the start of an element, the end of an element, the start of an attribute, the end of an attribute, and so on. In this phrase, we create an XMLReader instance using the SAXParser. After we have created the parser instance, we then set a content handler using the setContentHandler() method. The content handler is a class that defines the various callback methods that will be called ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.