Java Utililty Methods XML SAX Parser

List of utility methods to do XML SAX Parser

Description

The list of methods to do XML SAX Parser are organized into topic(s).

Method

SchemagetSchema(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);
SchemagetSchema(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;
...
SchemagetSchemaFromResource(URL schemaURL)
get Schema From Resource
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(schemaURL);
return schema;
XMLReadergetXIncludeXMLReader()
get X Include XML Reader
try {
    return saxParserFactory.newSAXParser().getXMLReader();
} catch (RuntimeException e) {
    throw e;
} catch (Exception e) {
    throw new RuntimeException(e);
XMLReadergetXmlReader()
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);
...
booleanisWellFormedXml(final String string)
is Well Formed Xml
return isWellFormedXml(new InputSource(new StringReader(string)));
booleanisXML(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
...
voidload(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);
SAXParserFactorynewInstance()
new Instance
return SAXParserFactory.newInstance();
XMLReadernewXMLReader()
new XML Reader
final SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(false);
spf.setNamespaceAware(true);
return spf.newSAXParser().getXMLReader();