/** * Create a SAX parser from the JAXP factory. The result can be used to parse XML files. * * <p>See class Javadoc for hints on setting an entity resolver. This parser has its entity * resolver set to the system entity resolver chain. * * @param validate if true, a validating parser is returned * @param namespaceAware if true, a namespace aware parser is returned * @throws FactoryConfigurationError Application developers should never need to directly catch * errors of this type. * @throws SAXException if a parser fulfilling given parameters can not be created * @return XMLReader configured according to passed parameters */ public static XMLReader createXMLReader(boolean validate, boolean namespaceAware) throws SAXException { SAXParserFactory factory; if (!validate && useFastSAXParserFactory) { try { factory = createFastSAXParserFactory(); } catch (ParserConfigurationException ex) { factory = SAXParserFactory.newInstance(); } catch (SAXException ex) { factory = SAXParserFactory.newInstance(); } } else { useFastSAXParserFactory = false; factory = SAXParserFactory.newInstance(); } factory.setValidating(validate); factory.setNamespaceAware(namespaceAware); try { return factory.newSAXParser().getXMLReader(); } catch (ParserConfigurationException ex) { throw new SAXException( "Cannot create parser satisfying configuration parameters", ex); // NOI18N } }
public void init() throws LagoonException { try { spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(false); spf.setFeature("http://xml.org/sax/features/namespaces", true); spf.setFeature("http://xml.org/sax/features/namespace-prefixes", false); spf.setFeature("http://xml.org/sax/features/validation", false); } catch (ParserConfigurationException e) { throw new Error("Unable to configure XML parser"); } catch (SAXException e) { throw new Error("Unable to configure XML parser"); } target = null; }
private static SAXParserFactory makeParserFactory(boolean validating, boolean ns) { SAXParserFactory factory = null; // create factory according to javax.xml.parsers.SAXParserFactory property // or platform default (i.e. com.sun...) try { factory = SAXParserFactory.newInstance(); factory.setValidating(validating); factory.setNamespaceAware(ns); } catch (FactoryConfigurationError err) { notifyFactoryErr(err, "javax.xml.parsers.SAXParserFactory"); // NOI18N throw err; } return factory; }
protected static SAXParser getParser(boolean validate) throws SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(validate); return factory.newSAXParser(); }