Java XML SAX Parser createXmlReader()

Here you can find the source of createXmlReader()

Description

create Xml Reader

License

Open Source License

Declaration

public static XMLReader createXmlReader() throws SAXException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Tasktop Technologies and others.
 * 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.ja  va2s . c o  m
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

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 {
    public static XMLReader createXmlReader() throws SAXException {
        try {
            // use Xerces to ensure XML 1.1 is handled correctly
            Class<?> clazz = Class.forName("org.apache.xerces.parsers.SAXParser"); //$NON-NLS-1$
            return (XMLReader) clazz.newInstance();
        } catch (Throwable e) {
            SAXParser saxParser;
            try {
                SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                saxParserFactory.setNamespaceAware(true);
                saxParser = saxParserFactory.newSAXParser();
            } catch (ParserConfigurationException e2) {
                throw new SAXException(e2);
            }
            return saxParser.getXMLReader();
        }
    }
}

Related

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