public static SAXParser buildSecureSaxParser() throws ParserConfigurationException,
            SAXNotRecognizedException, SAXNotSupportedException, SAXException {
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        return factory.newSAXParser();
    }
public static SAXParser buildSecureSaxParser ( ) throws ParserConfigurationException , SAXNotRecognizedException , SAXNotSupportedException , SAXException { final SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; factory . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; factory . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; return factory . newSAXParser ( ) ; }
Constructs a secure SAX Parser.

@return a SAX Parser
@throws javax.xml.parsers.ParserConfigurationException thrown if there is a parser
configuration exception
@throws org.xml.sax.SAXNotRecognizedException thrown if there is an unrecognized
feature
@throws org.xml.sax.SAXNotSupportedException thrown if there is a non-supported
feature
@throws org.xml.sax.SAXException is thrown if there is a org.xml.sax.SAXException