简体   繁体   English

Android上带有javax.xml.parsers的ParserConfigurationException

[英]ParserConfigurationException with javax.xml.parsers on Android

I'm trying to use javax.xml.parsers on Android but I always get a ParserConfigurationException when trying to set these two features : 我正在尝试在Android上使用javax.xml.parsers,但是在尝试设置这两个功能时总是会收到ParserConfigurationException:

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();
    }

Feature names are fully qualified URIs. 功能名称是完全限定的URI。 Implementations may define their own features. 实现可以定义自己的功能。 A ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. 如果此DocumentBuilderFactory或它创建的DocumentBuilders不支持该功能,则抛出ParserConfigurationException。 It is possible for a DocumentBuilderFactory to expose a feature value but be unable to change its state. DocumentBuilderFactory可能会公开特征值,但无法更改其状态。

The docs on developer.android.com says developer.android.com上的文档说

Feature names are fully qualified URIs. 功能名称是完全限定的URI。 Implementations may define their own features. 实现可以定义自己的功能。 An ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. 如果此DocumentBuilderFactory或它创建的DocumentBuilders不支持该功能,则抛出ParserConfigurationException。 It is possible for an DocumentBuilderFactory to expose a feature value but be unable to change its state. DocumentBuilderFactory可能会公开特征值,但无法更改其状态。

But it looks this feature exists in xerces.apache.org 但看起来此功能存在于xerces.apache.org中

So I guess it means these features (used for document validation) are not supported in Android SDK for now. 因此,我想这意味着这些功能(用于文档验证)暂时不支持Android SDK。

Just for information. 仅供参考。 I found these error using an Epub parser library available in Android Arsenal EpubParser . 我使用Android Arsenal EpubParser中可用的Epub解析器库发现了这些错误。 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XOM 与 javax.xml.parsers - XOM v/s javax.xml.parsers 导入javax.xml.parsers.ParserConfigurationException无法解决 - The import javax.xml.parsers.ParserConfigurationException cannot be resolved StatusLogger 捕获 javax.xml.parsers.ParserConfigurationException 设置功能 - StatusLogger Caught javax.xml.parsers.ParserConfigurationException setting feature 切换到log4j2后如何修复javax.xml.parsers.ParserConfigurationException? - How to fix javax.xml.parsers.ParserConfigurationException after switching to log4j2? gwt-user.jar 和 Java 11 - package javax.xml.parsers 可以从多个模块访问:<unnamed> , java.xml</unnamed> - gwt-user.jar with Java 11 - The package javax.xml.parsers is accessible from more than one module: <unnamed>, java.xml IBM jre javax.xml.parsers.FactoryConfigurationError - IBM jre javax.xml.parsers.FactoryConfigurationError javax.xml.parsers.SAXParserFactory ClassCastException - javax.xml.parsers.SAXParserFactory ClassCastException OpenNLP: documentBuilderFactory.setFeature(“http://javax.xml.XMLConstants/feature/secure-processing”, true) ParserConfigurationException - OpenNLP: documentBuilderFactory.setFeature(“http://javax.xml.XMLConstants/feature/secure-processing”, true) ParserConfigurationException org.xml.sax.SAXException: javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.SAXParserFactory cannot be created - org.xml.sax.SAXException: javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.SAXParserFactory cannot be created javax.xml.parsers.DocumentBuilder对复杂类型的支持 - javax.xml.parsers.DocumentBuilder support for complex types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM