List of utility methods to do XML SAX Parser
Schema | getSchema(File xsd, ErrorHandler errorHandler) Gets the schema. SchemaFactory schemaFactory = SchemaFactory.newInstance(HTTP_WWW_W3_ORG_2001_XML_SCHEMA);
schemaFactory.setErrorHandler(errorHandler);
return schemaFactory.newSchema(xsd);
|
Schema | getSchema(URL xml_schema) get Schema Schema schema = null; SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { schema = sf.newSchema(xml_schema); } catch (SAXException saxe) { throw new Error("Error while getting schema", saxe); return schema; ... |
Schema | getSchemaFromResource(URL schemaURL) get Schema From Resource SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(schemaURL);
return schema;
|
XMLReader | getXIncludeXMLReader() get X Include XML Reader try { return saxParserFactory.newSAXParser().getXMLReader(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); |
XMLReader | getXmlReader() Get an instance of an XML reader from the XMLReaderFactory. try { final XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); reader.setFeature("http://xml.org/sax/features/namespaces", true); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); return reader; } catch (final Exception e) { throw new RuntimeException("Unable to create XMLReader", e); ... |
boolean | isWellFormedXml(final String string) is Well Formed Xml return isWellFormedXml(new InputSource(new StringReader(string))); |
boolean | isXML(final byte[] data) Comprueba si los datos proporcionados son un XML válido. final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); try { final SAXParser parser = factory.newSAXParser(); final XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new ErrorHandler() { @Override ... |
void | load(InputStream is, DefaultHandler handler) load InputSource sheetSource = new InputSource(is);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader sheetParser = saxParser.getXMLReader();
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
|
SAXParserFactory | newInstance() new Instance return SAXParserFactory.newInstance();
|
XMLReader | newXMLReader() new XML Reader final SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating(false); spf.setNamespaceAware(true); return spf.newSAXParser().getXMLReader(); |