How to convert JSON to XML with namespace?

Please suggest me how to convert the JSON object to XML


From JSON,

{     "Multiply": {         "intA": 5, "intB": 5     } } 


<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap=""> <soap:Body>     <Multiply xmlns="">         <intA>5</intA>         <intB>5</intB>     </Multiply> </soap:Body> </soap:Envelope> 
Add Comment
1 Answer(s)

Consider XSLT 3.0 (available to Python users via Saxon/C).

<xsl:template name="xsl:initial-template" expand-text="yes">   <xsl:variable name="json" select="json-doc('my.json')"/>   <soap:Envelope xmlns:xsi=""                  xmlns:xsd=""                  xmlns:soap="">     <soap:Body>       <Multiply xmlns="">         <intA>{$json?Multiply?IntA}</intA>         <intB>{$json?Multiply?IntB}</intB>       </Multiply>     </soap:Body>   </soap:Envelope> </xsl:template> 

The advantage of this approach, compared with off-the-shelf json-to-xml conversion tools, is that it gives you total control over the XML output. (And of course you can go in the other direction as well).

Answered on July 17, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.