Java XML SAX Parser createSAXParser()

Here you can find the source of createSAXParser()

Description

Creates SAX parser and disables XXE

License

Open Source License

Exception

Parameter Description
ParserConfigurationException an exception
SAXException an exception

Return

new SAX parser

Declaration

public static SAXParser createSAXParser() throws ParserConfigurationException, SAXException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2017 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w  w.  j ava 2 s .c o  m*/
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;

public class Main {
    /**
     * Creates SAX parser and disables XXE
     * 
     * @return new SAX parser
     * @throws ParserConfigurationException
     * @throws SAXException
     */
    public static SAXParser createSAXParser() throws ParserConfigurationException, SAXException {

        SAXParserFactory factory = SAXParserFactory.newInstance();
        // Disable XML External Entity to avoid hack
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); //$NON-NLS-1$
        SAXParser parser = factory.newSAXParser();

        return parser;
    }
}

Related

  1. addMessagesToMap(final Map hangmanMap, String messagesURIString)
  2. canDisableExternalDtds(SAXParserFactory parserFactory)
  3. createNamespaceAwareSAXParserFactory()
  4. createSafeSaxReader(SAXParserFactory saxParserFactory, ContentHandler contentHandler)
  5. createSaxParser()
  6. createSAXParser(DefaultHandler dh)
  7. createSaxParserFactory()
  8. createSchema(String url)
  9. createXMLReader()