I use XSLT to convert the XML to JSON. I use XSLT instead of Jackson/org.json as XSLT retains the namespace information.
For example, for the below SOAP XML request,
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AccountDetailsRequest xmlns="http://com/blog/demo/webservices/accountservice">
<accountNumber>12345</accountNumber>
</AccountDetailsRequest>
</soap:Body>
</soap:Envelope>
converts it to the following JSON.
{"soap:Envelope":{"soap:Body":{"AccountDetailsRequest":{"accountNumber":"12345"}}}}
The namespace definition is lost. But, I plan to store the namespace definition in a map.
I use Jackson/org.json[both return similar results] to convert it back to XML and I get the following XML:
<soap:Envelope>
<soap:Body>
<AccountDetailsRequest>
<accountNumber>12345</accountNumber>
</AccountDetailsRequest>
</soap:Body>
</soap:Envelope>
The only part I am not able to figure out is the way to add the namespace definition assuming I can store that information in a map.
I considered adding a <root> </root>
with all the namespaces in it, as W3C standard specifies it is a valid way to do so. But SOAP does not accept such XML.
Any way to get back the XML with proper namespace information?