I'm trying to use javax.xml.parsers on Android but I always get a ParserConfigurationException when trying to set these two features :
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
Here is my code
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
factory.setValidating(false);
try {
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
The docs on developer.android.com says
But it looks this feature exists in xerces.apache.org
So I guess it means these features (used for document validation) are not supported in Android SDK for now.
Just for information. I found these error using an Epub parser library available in Android Arsenal EpubParser. I'm not the only one to have find this issue. Looks like there is a problem with this library because these two unsupported features are used regarding the code :
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);