DocumentBuilder中的parse方法返回错误 [英] parse method in DocumentBuilder is returning an error

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

问题描述

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

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

错误是:

DocumentBuilder类型中的方法parse(InputStream)不是 适用于参数(InputSource)

The method parse(InputStream) in the type DocumentBuilder is not applicable for the arguments (InputSource)

这是代码:

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方法返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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