DOMResult result = new DOMResult(null); transformer.toResult(normalizedMessage.getContent(), result); Document document = (Document) result.getNode();
Node node = transformer.toDOMNode(normalizedMessage); Document document = null; if (node instanceof Document) { document = (Document) node; } else if (node instanceof Element) { document = transformer.createDocument(); document.appendChild(node.cloneNode(true)); } else { throw new TransformerException("Could not create Document from Source"); }
    public SOAPMessage createSOAPMessage(NormalizedMessage normalizedMessage) throws SOAPException, IOException, TransformerException {        SOAPMessage soapMessage = getMessageFactory().createMessage();        addSoapProperties(soapMessage, normalizedMessage);        SOAPPart soapPart = soapMessage.getSOAPPart();        SOAPEnvelope envelope = soapPart.getEnvelope();        SOAPBody body = envelope.getBody();        // lets turn the payload into a DOM Node to avoid blatting over the envelope        DOMResult result = new DOMResult(null);        transformer.toResult(normalizedMessage.getContent(), result);        Document document = (Document) result.getNode();        body.addDocument(document);        addSoapAttachments(soapMessage, normalizedMessage);        if (log.isDebugEnabled()) {            ByteArrayOutputStream buffer = new ByteArrayOutputStream();            soapMessage.writeTo(buffer);            log.debug(new String(buffer.toByteArray()));        }        return soapMessage;    }