我正在修復關於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