Code example for SAXParserFactory

Methods: setFeature, setNamespaceAware

0
     */ 
    public SAXParserFactory getSAXParserFactory() {
        SAXParserFactory factory = get(SAXParserFactory.class);
        if (factory == null) {
            factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            try { 
                factory.setFeature(
                        XMLConstants.FEATURE_SECURE_PROCESSING, true);
            } catch (ParserConfigurationException e) {
            } catch (SAXNotSupportedException e) {
            } catch (SAXNotRecognizedException e) {
                // TIKA-271: Some XML parsers do not support the 
                // secure-processing feature, even though it's required by 
                // JAXP in Java 5. Ignoring the exception is fine here, as 
                // deployments without this feature are inherently vulnerable 
                // to XML denial-of-service attacks. 
            } 
        } 
        return factory;
    }