O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required