OpenNLP:documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing",true)ParserConfigurationException [英] OpenNLP: documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true) ParserConfigurationException

查看:162
本文介绍了OpenNLP:documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing",true)ParserConfigurationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在Android Studio中使用OpenNLP,但我的应用程序始终在OpenNLP在其XmlUtil类中使用的这段代码中抛出 ParserConfigurationException 修改:

So i'm trying to use OpenNLP within Android Studio, but my application always throws a ParserConfigurationException within this body of code that is used by OpenNLP in their XmlUtil class, which that I am unable to modify:

public static DocumentBuilder createDocumentBuilder() {
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        return documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException var1) {
        throw new IllegalStateException(var1);
    }
}

documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing",true); 导致应用程序引发 ParserConfigurationException .

现在被困了大约一个星期并且没有运气,关于如何解决此错误的任何提示?

Been stuck on this for about a week now and no luck, any tips for how I can get around this error?

推荐答案

因此,事实证明,使用给定的URL"

So it turns out that using the given URL "http://javax.xml.XMLConstants/feature/secure-processing" corresponds to XMLConstants.FEATURE_SECURE_PROCESSING -> When the XMLUtils class uses this to set the feature of the documentBuilderFactory -> it will always throw an Exception because this XMLConstant is not recognized for some reason.

为了解决此问题,并且由于XMLUtil.java类在使用时/在opennlp-tools-1.8.3.jar文件中被抓取,因此无法修改:

In order to remedy this problem and because XMLUtil.java class was unmodifiable as it was being used / grabbed within the opennlp-tools-1.8.3.jar file:

我需要将opennlp-tools-1.8.3.jar提取到其.class文件中,然后使用ClassEditor(用于编辑.class文件的程序)来更改要设置的功能:

I needed to extract the opennlp-tools-1.8.3.jar down to its .class files and then use ClassEditor (a program for editing .class files) in order to change which feature was being set:

我将XMLUtil.java文件中功能的值更改为另一个不会导致该函数引发异常的值:

I changed the value of the feature within the XMLUtil.java file to another that would not cause this function to throw an exception:

public static DocumentBuilder createDocumentBuilder() {
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        return documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException var1) {
        throw new IllegalStateException(var1);
    }
}

这使我能够处理以前无法修改的XMLUtil.java文件,现在documentBuilderFactory.setFeature将不会引发异常,从而使我可以使用OpenNLP库中经过稍微修改的代码!

This allowed me to work around the previously unmodifiable XMLUtil.java file and now documentBuilderFactory.setFeature will not throw an Exception, allowing me to use the slightly modified code within the OpenNLP library!

这篇关于OpenNLP:documentBuilderFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing",true)ParserConfigurationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆