本文介绍了DocumentBuilder中的parse方法返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用采用InputSource来解析DocumentBuilder实例的parse方法.

I am trying to use the parse method that takes an InputSource to parse a DocumentBuilder instance.

错误是:

这是代码:

public static Document loadXMLFromString(String xml) throws Exception {
    DocumentBuilder factory = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = factory.parse(new InputSource(new StringReader(xml)));   
}

它要我更改为InputStream..检查了文档,并且DocumentBuilder中的解析方法之一采用了InputSource.问题是什么?

It is asking me to change to InputStream.. Checked the documentation and one of the parse methods in DocumentBuilder takes an InputSource. What is the problem?

推荐答案

问题可能是由于错误导入类InputSource引起的.请org.xml.sax.InputSource已导入.

The problem may be due to a bad import of class InputSource.Please org.xml.sax.InputSource is imported .

DocumentBuilder接受org.xml.sax.InputSource,但不接受jdk.internal.org.xml.sax.InputSource

这篇关于DocumentBuilder中的parse方法返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:31