简体   繁体   中英

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;
}

Method with debugger

Can you please post your respBody String here. Is it a well-formed XML without unnecessary special characters like \\n. Please note - Windows usually end lines with CR+LF; MacOS X and Linux, LF; classic Mac OS, CR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM