Java tutorial
//package com.java2s; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; public class Main { /** * Equivalent to {@link #newSAXParser(boolean, boolean, boolean) * newSAXParser(true, false, false)}. */ public static SAXParser newSAXParser() throws ParserConfigurationException, SAXException { return newSAXParser(true, false, false); } /** * Convenience method: creates and returns a SAXParser. * * @param namespaceAware specifies whether the parser produced * by this code will provide support for XML namespaces * @param validating specifies whether the parser produced by * this code will validate documents against their DTD * @param xIncludeAware specifies whether the parser produced by * this code will process XIncludes * @return newly created SAXParser * @exception ParserConfigurationException if a parser cannot be created * which satisfies the requested configuration * @exception SAXException for SAX errors */ public static SAXParser newSAXParser(boolean namespaceAware, boolean validating, boolean xIncludeAware) throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); factory.setValidating(validating); factory.setXIncludeAware(xIncludeAware); // For Xerces which otherwise, does not support "x-MacRoman". try { factory.setFeature("http://apache.org/xml/features/allow-java-encodings", true); } catch (Exception ignored) { } return factory.newSAXParser(); } }