builder.parse((new StringReader(xml)) returns DeferredDocumentImpl
<p>I am trying to understand what mistake I could have made but can't find the solution.</p>

<pre>public static Document getXMLFromString(String xml) {
        org.w3c.dom.Document doc = null;
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory
                    .newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder;
            builder = factory.newDocumentBuilder();
            doc = (org.w3c.dom.Document) builder.parse(new InputSource(
                    new StringReader(xml)));
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        return doc;
    }</pre>

<p>I did import org.w3c.dom.Document</p>

<p>I am calling this method here:</p>

<pre>
private Node getAuthToken(SOAPMessage responseAuth) throws SOAPException,
            TransformerException, ParserConfigurationException, IOException,
            SAXException {
        String s = indentXML(responseAuth.getSOAPPart().getContent());
        Document doc = getXMLFromString(s);
        NodeList authTokenNodeList = doc.getElementsByTagName("authToken");
        return authTokenNodeList.item(0);
    }
</pre>

<p>The NodeList is empty.</p>

<p>After researching on the web, everybody uses this code to parse a string to a Document. I do not have any exception but after calling the method parse(), the value of doc is set to [#document: null] DeferredDocumentImpl.</p>

<p>I am using everything from the org.w3c.dom.</p>

<p>xml is a string that contains</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
&lt;soap:Header&gt;
&lt;context xmlns="urn:zimbra"&gt;
&lt;session id="36" type="admin"&gt;36&lt;/session&gt;
&lt;change token="251"/&gt;
&lt;/context&gt;
&lt;/soap:Header&gt;
&lt;soap:Body&gt;
&lt;AuthResponse xmlns="urn:zimbraAdmin"&gt;
&lt;authToken&gt;...&lt;/authToken&gt;
&lt;lifetime&gt;...&lt;/lifetime&gt;
&lt;a n="zimbraIsDomainAdminAccount"&gt;false&lt;/a&gt;
&lt;session id="36" type="admin"&gt;36&lt;/session&gt;
&lt;/AuthResponse&gt;
&lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;
</code></pre>

<p>Here is how I built the string after a SOAP call:</p>

<pre>String xml = indentXML(responseAuth.getSOAPPart().getContent());</pre>

<p>What am I doing wrong?</p>

<p>This is what I am trying to do in a simple way:</p>

<pre>StringBuilder soapResponse = new StringBuilder(...
...
...
);

        org.w3c.dom.Document doc = null;
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory
                    .newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder builder;
            builder = factory.newDocumentBuilder();
            doc = (org.w3c.dom.Document) builder.parse(new InputSource(
                    new StringReader(soapResponse.toString())));
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        NodeList authTokenNodeList = doc.getElementsByTagName("authToken");
        Node n = authTokenNodeList.item(0);
        String s = n.getNodeValue();</pre>
