Java XML Namespace createXMLReader(boolean validating, boolean withNamespace)

Here you can find the source of createXMLReader(boolean validating, boolean withNamespace)

Description

Create an XMLReader instance.

License

Open Source License

Parameter

Parameter Description
validating true if a validating parser is desired
withNamespace true if the parser is namespace aware

Exception

Parameter Description
SAXException If no XMLReader could be created.

Return

The created instance.

Declaration

public static XMLReader createXMLReader(boolean validating, boolean withNamespace) throws SAXException 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 *****************************************************************************/

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

public class Main {
    private static final SAXParserFactory parserFactory = SAXParserFactory.newInstance();

    /**//from  ww w  . j  a va  2 s.  c o  m
     * Create an XMLReader instance.
     * 
     * @param validating
     *            true if a validating parser is desired
     * @param withNamespace
     *            true if the parser is namespace aware
     * @return The created instance.
     * @throws SAXException
     *             If no XMLReader could be created.
     */
    public static XMLReader createXMLReader(boolean validating, boolean withNamespace) throws SAXException {
        try {
            synchronized (parserFactory) {
                parserFactory.setValidating(validating);
                parserFactory.setNamespaceAware(withNamespace);
                return parserFactory.newSAXParser().getXMLReader();
            }
        } catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
}

Related

  1. compile(String expression, NamespaceContext namespaceContext)
  2. createNamespaceContext(final String nsPrefix, final String nsUri)
  3. createXMLReader(boolean validating, boolean namespaceAware)
  4. getBaseNamespace(InputStream owlStream)
  5. getBuilder(boolean ignoreComments, boolean validating, boolean ignoreContentWhitespace, boolean isNamespaceAware)
  6. getCarbonNamespace()
  7. getDefaultNamespaceURI(final XMLStreamWriter writer)