Java tutorial
//package com.java2s; /* * This file is part of the DiffX library. * * For licensing information please see the file license.txt included in the release. * A copy of this licence can also be found at * http://www.opensource.org/licenses/artistic-license-2.0.php */ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; public class Main { /** * Creates a non-validating, non-namespace-aware {@link XMLReader} using the specified * {@link ContentHandler}. * * <p>If the given {@link ContentHandler} is <code>null</code>, the {@link XMLReader} is * not initialised. * * @param handler The content handler to use. * * @return The requested {@link XMLReader} * * @throws SAXException Should a SAX exception occur * @throws ParserConfigurationException Should a parser config exception occur */ public static XMLReader makeXMLReader(ContentHandler handler) throws SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(false); factory.setValidating(false); XMLReader reader = factory.newSAXParser().getXMLReader(); if (handler != null) { reader.setContentHandler(handler); } return reader; } }