List of usage examples for javax.xml.parsers SAXParserFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:Main.java
public static SAXParserFactory getSAXFactory() { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); return factory; }
From source file:Main.java
public static SAXParser getParser() throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false);/* w w w.j ava2 s . c om*/ factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); return factory.newSAXParser(); }
From source file:Main.java
/** * To get a SAXParserFactory instance which is then used to obtain an {@link SAXParser} instance. * /*from ww w . j av a 2 s . c o m*/ * @param namespaces Whether to provide namespace support. * @param validation Whether to produce a validating SAX parser. * @return the SAXParserFactory for further use */ public static SAXParserFactory getSAXParserFactory(final boolean validation, final boolean namespaces) { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaces); factory.setValidating(validation); return factory; }
From source file:Main.java
public static synchronized SAXParserFactory getSAXFactory() { if (SAX_FACTORY == null) { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); SAX_FACTORY = factory;//from www. j a v a 2 s . c om } return SAX_FACTORY; }
From source file:Main.java
/** Creates a namespace-aware {@link SAXParserFactory} */ private static SAXParserFactory createNamespaceAwareSAXParserFactory() { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); return spf;//from ww w . j a va2 s .c om }
From source file:Main.java
public static void saxParserValidation(InputStream streamDaValidare, InputStream inputSchema, DefaultHandler handler) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); if (inputSchema != null) { factory.setValidating(true);/*from w w w.j a v a 2 s .c o m*/ } else { factory.setValidating(false); } SAXParser parser = factory.newSAXParser(); if (inputSchema != null) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); parser.setProperty(JAXP_SCHEMA_SOURCE, inputSchema); } parser.parse(streamDaValidare, handler); }
From source file:Main.java
/** * Creates a non-validating, non-namespace-aware {@link XMLReader} using the specified * {@link ContentHandler}./*from w w w . j a v a2 s .c om*/ * * <p>If the given {@link ContentHandler} is <code>null</code>, the {@link XMLReader} is * not initialised. * * @param handler The content handler to use. * * @return The requested {@link XMLReader} * * @throws SAXException Should a SAX exception occur * @throws ParserConfigurationException Should a parser config exception occur */ public static XMLReader makeXMLReader(ContentHandler handler) throws SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(false); factory.setValidating(false); XMLReader reader = factory.newSAXParser().getXMLReader(); if (handler != null) { reader.setContentHandler(handler); } return reader; }
From source file:Main.java
/** * Convenience method: creates and returns a SAXParser. * /*w w w . j a v a 2 s . com*/ * @param namespaceAware specifies whether the parser produced * by this code will provide support for XML namespaces * @param validating specifies whether the parser produced by * this code will validate documents against their DTD * @param xIncludeAware specifies whether the parser produced by * this code will process XIncludes * @return newly created SAXParser * @exception ParserConfigurationException if a parser cannot be created * which satisfies the requested configuration * @exception SAXException for SAX errors */ public static SAXParser newSAXParser(boolean namespaceAware, boolean validating, boolean xIncludeAware) throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); factory.setValidating(validating); factory.setXIncludeAware(xIncludeAware); // For Xerces which otherwise, does not support "x-MacRoman". try { factory.setFeature("http://apache.org/xml/features/allow-java-encodings", true); } catch (Exception ignored) { } return factory.newSAXParser(); }
From source file:Main.java
public static SAXParserFactory createParserFactory() { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false);//from ww w .j av a 2 s.c o m try { factory.setFeature("http://xml.org/sax/features/external-general-entities", false); factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); } catch (ParserConfigurationException ex) { } catch (SAXNotRecognizedException ex) { } catch (SAXNotSupportedException ex) { } try { factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (ParserConfigurationException ex) { } catch (SAXNotRecognizedException ex) { } catch (SAXNotSupportedException ex) { } return factory; }
From source file:Main.java
public static XMLReader createXmlReader() throws SAXException { try {/*w w w . j a v a2 s. c o m*/ // 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(); } }