XML Catalog - Using A Catalog - Java SAX Example

Java SAX Example

Catalog resolvers are available for various programming languages. The following example shows how, in Java, a SAX parser may be created to parse some input source in which the org.apache.xml.resolver.tools.CatalogResolver is used to resolve external entities to locally-cached instances. This resolver originates from Apache Xerces but is now included with the Sun Java runtime.

Simply create a SAXParser in the normal way, using factories. Obtain the XML reader and set the entity resolver to the standard one (CatalogResolver) or another of your own.

final SAXParser saxParser = SAXParserFactory.newInstance.newSAXParser; final XMLReader reader = saxParser.getXMLReader; final ContentHandler handler = ...; final InputSource input = ...; reader.setEntityResolver( new CatalogResolver ); reader.setContentHandler( handler ); reader.parse( input );

It is important to call the parse method on the reader, not on the SAX parser.

Read more about this topic:  XML Catalog, Using A Catalog