我正在修复关于DocumentBuilder.parse的现有代码上的错误。我有下面的代码:DocumentBuilder.parse(InputStream)返回null
String theOutput;
theOutput = response.encodeURL(prefix + "/include/sampleForConversion.jsp?" + request.getQueryString();
StreamSource xmlSource = new StreamSource(new URL(theOutput).openStream(), "http://sampleApps.net/static/dataDef1.1.dtd");
Document xmlDoc = dBuilder.parse(xmlSource.getInputStream());
我不明白为什么我对xmlDoc中得到一个空值,虽然我有theOutput和xmlSource变量有效值。请帮忙。
谢谢!
只是为了说明:你有'(xmlDoc == null)= true'还是你得到一个空文件('[[#document:null]')?解析方法应该返回一个文档或抛出一个异常,但永远不会返回'null' ... – 2010-01-07 08:39:26
hi Adreas, 我得到[#document:null] – 2010-01-07 08:53:30
'[#document:null]'不代表空文档,这只是'Document'的'toString()'输出写得很糟糕。 – skaffman 2010-01-07 09:57:41