繁体   English   中英

Android上带有javax.xml.parsers的ParserConfigurationException

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

我正在尝试在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);

这是我的代码

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

功能名称是完全限定的URI。 实现可以定义自己的功能。 如果此DocumentBuilderFactory或它创建的DocumentBuilders不支持该功能,则抛出ParserConfigurationException。 DocumentBuilderFactory可能会公开特征值,但无法更改其状态。

developer.android.com上的文档说

功能名称是完全限定的URI。 实现可以定义自己的功能。 如果此DocumentBuilderFactory或它创建的DocumentBuilders不支持该功能,则抛出ParserConfigurationException。 DocumentBuilderFactory可能会公开特征值,但无法更改其状态。

但看起来此功能存在于xerces.apache.org中

因此,我想这意味着这些功能(用于文档验证)暂时不支持Android SDK。

仅供参考。 我使用Android Arsenal EpubParser中可用的Epub解析器库发现了这些错误。 我不是唯一发现此问题的人。 该库似乎有问题,因为这两个不支持的功能用于代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM