EntityResolver
Can be used for resolving entities during the parsing[1]
XMLSAXParser
class works with the ResolverSAXHandler handler.
Locale.forLanguageTag("")
rather than Locale.forLanguageTag("en")
to get the proper Locale
because there is no message*_en
localized message file for the underlying JDK Xerces parser.
XMLSAXParser
XMLSAXParser
instance to parse XML files inside zip files by XMLSAXParser.setAllowNestableConnections(boolean)Files.newBufferedReader(path, charset)
method to be sure that the correct encoding will be use regardless of the platform encoding.Reader reader = new InputStreamReader(url.openStream());As you can see, the default platform Charset was used (no Charset was specified to decode the file), which could lead to decoding problems in the XML files with special characters if the default platform Charset was not UTF-8.
http://apache.org/xml/features/xinclude
property. In that case, the included XML documents will not be taken into account by the parser even if the XMLSAXParser.setXIncludeAware(boolean) is set to true. It is however still possible to take into account included XML documents by setting the XMLSAXParser.setConcatenateIncludes(boolean) method to true.
XMLParserConfiguration config = new XMLParserConfiguration(); config.isValidating = false; XMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setParserConfiguration(config);
XMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", false);
XMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setProperty("namespace-prefixes", true);
XMLSAXParser.setSAXParserFactoryImplementation("com.ctc.wstx.sax.WstxSAXParserFactory"); XMLSAXParser parser = new XMLSAXParser("My Parser");
XMLSAXParser
class allows to use several types of inputs for the parsing:Reader
class may not be reused again (in our case after the Schema validation phase). In this use case, use instead the XMLSAXParser.parse(ReaderProvider) methodXMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setValidating(true); parser.setHandlerDTD(dtd); parser.setHandler(handler); parse.parse(file);
XMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setValidating(true); parser.setSchema(schema); parser.setHandler(handler); parse.parse(file);
XMLSAXParser parser = new XMLSAXParser("My Parser"); parser.setValidating(true); parser.setSchema(schema); parser.setHandler(handler); parser.showExceptions(false); parse.parse(file); if (handler.hasParserExceptions()) { List>ResolverSAXHandler.ExceptionResult> results = handler.getExceptionResults(); }
Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences