[英]Java: Getting [#document: null] when trying to parse a XML string into a Document object
I'm getting a null document object but not sure why - it's not really clear from the debugger. 我得到一个空文档对象,但不确定为什么-从调试器中还不清楚。
public Document parseResponse(String respBody) throws ParserConfigurationException, IOException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource source = new InputSource();
source.setCharacterStream(new StringReader(respBody));
Document doc = builder.parse(source);
return doc;
}
Can you please post your respBody
String here. 您能在这里发布您的
respBody
字符串respBody
? Is it a well-formed XML without unnecessary special characters like \\n. 它是格式正确的XML,没有不必要的特殊字符,例如\\ n。 Please note - Windows usually end lines with CR+LF;
请注意-Windows通常以CR + LF结尾行; MacOS X and Linux, LF;
MacOS X和Linux,LF; classic Mac OS, CR.
经典Mac OS,CR。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.