Java XML SAX Parser createXmlReader()

Here you can find the source of createXmlReader()

Description

Creates an XMLReader with default feature set.

License

Open Source License

Exception

Parameter Description
SAXException an exception
ParserConfigurationException an exception

Return

XMLReader

Declaration

public static XMLReader createXmlReader() throws SAXException, ParserConfigurationException 

Method Source Code


//package com.java2s;
/*//from   w ww  . j  a v a  2  s .  co m
 * JBoss, Home of Professional Open Source.
 *
 * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
 *
 * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
 */

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

public class Main {
    /**
     * Creates an XMLReader with default feature set.
     * 
     * @return XMLReader
     * @throws SAXException
     * @throws ParserConfigurationException
     */
    public static XMLReader createXmlReader() throws SAXException, ParserConfigurationException {
        SAXParserFactory spf = SAXParserFactory.newInstance();

        // Create a JAXP SAXParser
        SAXParser saxParser = spf.newSAXParser();

        // Get the encapsulated SAX XMLReader
        XMLReader reader = saxParser.getXMLReader();

        // set default features
        reader.setFeature("http://xml.org/sax/features/namespaces", true);

        return reader;
    }
}

Related

  1. createSAXParser(DefaultHandler dh)
  2. createSaxParserFactory()
  3. createSchema(String url)
  4. createXMLReader()
  5. createXmlReader()
  6. createXmlReader()
  7. extractClasses(String xmlContent)
  8. getFactory()
  9. getSAXParser()