O'Reilly logo

Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition by Ivor Horton

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

22.9. Accessing Parsers

The javax.xml.parsers package defines four classes supporting the processing of XML documents:

SAXParserFactoryEnables you to create a configurable factory object that you can use to create a SAXParser object encapsulating a SAX-based parser
SAXParserDefines an object that wraps a SAX-based parser
DocumentBuilderFactoryEnables you to create a configurable factory object that you can use to create a DocumentBuilder object encapsulating a DOM-based parser
DocumentBuilderDefines an object that wraps a DOM-based parser

All four classes are abstract. This is because JAXP is designed to allow different parsers and their factory classes to be plugged in. Both DOM and SAX parsers are developed independently of the Java JDK so it is important to be able to integrate new parsers as they come along. The Xerces parser that is currently distributed with the JDK is controlled and developed by the Apache Project, and it provides a very comprehensive range of capabilities. However, you may want to take advantage of the features provided by other parsers from other organizations, and JAXP allows for that.

These abstract classes act as wrappers for the specific factory and parser objects that you need to use for a particular parser and insulate your code from a particular parser implementation. An instance of a factory object that can create an instance of a parser is created at run time, so your program can use a different parser without changing or even recompiling your code. ...

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