7

I am trying to create a soap message with the following structure:

<SOAP:Envelope>
    <SOAP:Header/>
    <SOAP:Body>
        <Item1/>
        <Item2/>
    </SOAP:Body>
</SOAP:Envelope>

I am using a WebServiceMessageCallback to get the above format, but when I try and transform the body with the new source, where source has the above format:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(source, soapBody.getPayloadResult());

I get the following error:

[Fatal Error] :1:157: The markup in the document following the root element must be well-formed.
ERROR:  'The markup in the document following the root element must be well-formed.'
    Exception in thread "main" org.springframework.ws.client.WebServiceTransformerException:Transformation error: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; The markup in the document following the root element must be well-formed.; nested exception is javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 157; The markup in the document following the root element must be well-formed.

My understanding is that this error is telling me that the body is not well-formed XML because it doesn't have a single root element. However, that is what I need as the service I am sending the message to expects the above structure.

Is there some way around this? Thanks for any help.

EDIT: I should mention that I have seen Spring Update SOAP Header with Two Elements, which is what I am trying to do but in the header instead. I have tried his method of using a dummy root, but I am not sure how to remove the dummy root after the transformation as he mentions. I don't have enough rep to comment on his answer to find out...

4

1 回答 1

0

该元素<SOAP:Body>包含您要交换的消息。因此,在 a 中放入两个元素<SOAP:Body>是不可能的。您必须在两个项目周围包装一个根 XML 元素。

于 2013-05-28T14:36:15.467 回答