I have this problem where I need to send to soap webservice that requires the root tag to have an xml data, this the xml that I’m trying to send:
<root><test key="Applicants">this is a data</test></root>
I need to append this to the SoapBody object as a document with this code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setExpandEntityReferences(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document result = builder.parse(new ByteArrayInputStream(request.getRequest().getBytes()));
Then adding it to the SoapBody to be sent to the webservice.
However, upon sending this request and tracing the logs, it’s actually reverting the " character to literal quotes (“)
This is the xml being sent:
<root><test key="Applicants">this is a data</test></root>
As you can see, the ” is being transformed to literal quotes, how can I keep the original data within root tag (which has the ")? It seems to be transforming it when I’m converting it to a Document object.
Would appreciate any help. Thanks.
Edit:
The webservice actually requires this format (from their documentation and sample xml requests), if this isn’t possible, is it a limitation? Should I user another framework?
Advertisement
Answer
The "
and "
are completely equivalent in this context. You haven’t actually said whether this is causing a problem: if it is, then it’s because some recipient of the XML isn’t processing it correctly. Incidentally, it would also be legitimate to convert the >
to >
.
When you parse XML and re-serialise it, irrelevant details like redundant whitespace get lost – just as if you copy this text into your text editor, the line-wrapping and font size gets lost.