List of usage examples for javax.xml.parsers SAXParserFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:xbird.xquery.dm.instance.DocumentTableModel.java
private static final XMLReader getXMLReader(final DocumentTableBuilder handler, final boolean parseAsHtml, final boolean resolveEntity) { final XMLReader myReader; try {//from w ww . j a v a 2 s . c om if (parseAsHtml) { Class clazz = ClassResolver.get(HTML_PARSER_CLASS); assert (clazz != null); myReader = ObjectUtils.<XMLReader>instantiate(clazz); } else { final SAXParserFactory factory; if (hasSunXerces) { factory = ObjectUtils .instantiate("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", null); } else { factory = SAXParserFactory.newInstance(); } factory.setNamespaceAware(true); SAXParser parser = factory.newSAXParser(); myReader = parser.getXMLReader(); } } catch (Exception e) { throw new XQRTException("Creating SAX XMLReader failed", e); } // setup handlers (requires saxHandler) myReader.setContentHandler(handler); try { myReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); myReader.setFeature("http://xml.org/sax/features/validation", true); // Validate the document and report validity errors. if (!parseAsHtml) { myReader.setFeature("http://apache.org/xml/features/validation/dynamic", true); // The parser will validate the document only if a grammar is specified. myReader.setFeature("http://apache.org/xml/features/validation/schema", true); // Turn on XML Schema validation by inserting an XML Schema validator into the pipeline. } } catch (Exception e) { throw new XQRTException("Configuaring SAX XMLReader failed.", e); } // setup entity resolver if (resolveEntity) { org.apache.xml.resolver.CatalogManager catalog = org.apache.xml.resolver.CatalogManager .getStaticManager(); catalog.setIgnoreMissingProperties(true); catalog.setPreferPublic(true); catalog.setUseStaticCatalog(false); EntityResolver resolver = new org.apache.xml.resolver.tools.CatalogResolver(catalog); myReader.setEntityResolver(resolver); } return myReader; }