簡體   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