Listing 2. Using the XMLReaderFactory to get an XMLReader instance (parser independent but requiring manual changes)
// Obtain an instance of an XMLReader implementation
XMLReader parser =
org.xml.sax.helpers.XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
// Do normal parsing tasks
parser.setContentHandler(new MyContentHandler());
parser.parse(new InputSource("file:///usr/local/projects/xml/test.xml");
|
