List of utility methods to do XML SAX Parser
void | addMessagesToMap(final Map add Messages To Map DefaultHandler handler = new DefaultHandler() { String name; String value; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { name = attributes.getValue("name"); public void characters(char[] ch, int start, int length) throws SAXException { ... |
boolean | canDisableExternalDtds(SAXParserFactory parserFactory) can Disable External Dtds if (canDisableExternalDtds == null) { try { parserFactory.getFeature(XERCES_LOAD_EXTERNAL_DTD); canDisableExternalDtds = Boolean.TRUE; } catch (Exception ex) { canDisableExternalDtds = Boolean.FALSE; return canDisableExternalDtds.booleanValue(); |
SAXParserFactory | createNamespaceAwareSAXParserFactory() Creates a namespace-aware SAXParserFactory SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
return spf;
|
XMLReader | createSafeSaxReader(SAXParserFactory saxParserFactory, ContentHandler contentHandler) create Safe Sax Reader if (saxParserFactory == null) { throw new IllegalArgumentException("The provided SAX parser factory cannot be null"); if (contentHandler == null) { throw new IllegalArgumentException("The provided SAX content handler cannot be null"); saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); ... |
SAXParser | createSaxParser() Create a new SAXParser which processes XML securely. SAXParserFactory spf = SAXParserFactory.newInstance(); try { spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); return spf.newSAXParser(); } catch (ParserConfigurationException | SAXException e) { throw new IllegalStateException(e); |
SAXParser | createSAXParser() Creates SAX parser and disables XXE SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); SAXParser parser = factory.newSAXParser(); return parser; |
SAXParser | createSAXParser(DefaultHandler dh) create SAX Parser try { SAXParser sp = spf.newSAXParser(); if (dh instanceof LexicalHandler) sp.setProperty("http://xml.org/sax/properties/lexical-handler", dh); return sp; } catch (ParserConfigurationException e) { throw new SAXException(e); |
SAXParserFactory | createSaxParserFactory() create Sax Parser Factory SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setValidating(true);
saxParserFactory.setNamespaceAware(true);
return saxParserFactory;
|
Schema | createSchema(String url) create Schema SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { return factory.newSchema(new URL(url)); } catch (MalformedURLException | SAXException e) { throw new RuntimeException(e); |
XMLReader | createXMLReader() Create a simple parser. return createXMLReader(false, false);
|