title: How to create a SOAP Request BODY from JSON?
body: <p>I have created a <code>node.js</code> application to create a SOAP Request BODY from a JSON object. I have the following code</p>
  
  <pre><code>var convert = require('xml-js');
  var xml = `&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:tem="http://tempuri.org/" xmlns:tel="http://schemas.datacontract.org" 
  xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
  &lt;soapenv:Header/&gt;
  &lt;soapenv:Body&gt;
  &lt;tem:MyRequest&gt;
   &lt;tem:request&gt;
  &lt;tel:MyTag1&gt;null&lt;/tel:MyTag1&gt;
  &lt;tel:MyTag2&gt;12&lt;/tel:MyTag2&gt;
  &lt;tel:MyTag3&gt;MyValue1&lt;/tel:MyTag3&gt;
  &lt;tel:MyTag4&gt;&lt;arr:int&gt;1000&lt;/arr:int&gt;
  &lt;arr:int&gt;1001&lt;/arr:int&gt;&lt;arr:int&gt;1002&lt;/arr:int&gt;
  &lt;/tel:MyTag4&gt;
  &lt;/tem:request&gt;
  &lt;/tem:MyRequest&gt;
  &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;`;
  
  var options = { ignoreComment: false, alwaysChildren: true };
  var result1 = convert.xml2js(xml, options);
  console.log("json = ",JSON.stringify(result1));
  
  
  var options2 = {compact: true, ignoreComment: true, spaces: 4};
  var result2 = convert.json2xml(result1, options2);
  console.log("xml ==&gt; ",result2);
  </code></pre>
  
  <p>I got output like this</p>
  
  <pre><code>json =  {"elements":[{"type":"element","name":"soapenv:Envelope","attributes":{"xmlns:soapenv":"http://schemas.xmlsoap.org/soap/envelope/","xmlns:tem":"http://tempuri.org/","xmlns:tel":"http://schemas.datacontract.org","xmlns:arr":"http://schemas.microsoft.com/2003/10/Serialization/Arrays"},"elements":[{"type":"element","name":"soapenv:Header","elements":[]},{"type":"element","name":"soapenv:Body","elements":[{"type":"element","name":"tem:MyRequest","elements":[{"type":"element","name":"tem:request","elements":[{"type":"element","name":"tel:MyTag1","elements":[{"type":"text","text":"null"}]},{"type":"element","name":"tel:MyTag2","elements":[{"type":"text","text":"12"}]},{"type":"element","name":"tel:MyTag3","elements":[{"type":"text","text":"MyValue1"}]},{"type":"element","name":"tel:MyTag4","elements":[{"type":"element","name":"arr:int","elements":[{"type":"text","text":"1000"}]},{"type":"element","name":"arr:int","elements":[{"type":"text","text":"1001"}]},{"type":"element","name":"arr:int","elements":[{"type":"text","text":"1002"}]}]}]}]}]}]}]}
  
  
  xml ==&gt;  &lt;elements&gt;
      &lt;type&gt;element&lt;/type&gt;
      &lt;name&gt;soapenv:Envelope&lt;/name&gt;
      &lt;attributes&gt;
          &lt;xmlns:soapenv&gt;http://schemas.xmlsoap.org/soap/envelope/&lt;/xmlns:soapenv&gt;
          &lt;xmlns:tem&gt;http://tempuri.org/&lt;/xmlns:tem&gt;
          &lt;xmlns:tel&gt;http://schemas.datacontract.org&lt;/xmlns:tel&gt;
       &lt;xmlns:arr&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays&lt;/xmlns:arr&gt;
      &lt;/attributes&gt;
      &lt;elements&gt;
          &lt;type&gt;element&lt;/type&gt;
          &lt;name&gt;soapenv:Header&lt;/name&gt;
      &lt;/elements&gt;
      &lt;elements&gt;
          &lt;type&gt;element&lt;/type&gt;
          &lt;name&gt;soapenv:Body&lt;/name&gt;
          &lt;elements&gt;
              &lt;type&gt;element&lt;/type&gt;
              &lt;name&gt;tem:MyRequest&lt;/name&gt;
              &lt;elements&gt;
                  &lt;type&gt;element&lt;/type&gt;
                  &lt;name&gt;tem:request&lt;/name&gt;
                  &lt;elements&gt;
                      &lt;type&gt;element&lt;/type&gt;
                      &lt;name&gt;tel:MyTag1&lt;/name&gt;
                      &lt;elements&gt;
                          &lt;type&gt;text&lt;/type&gt;
                          &lt;text&gt;null&lt;/text&gt;
                      &lt;/elements&gt;
                  &lt;/elements&gt;
                  &lt;elements&gt;
                      &lt;type&gt;element&lt;/type&gt;
                      &lt;name&gt;tel:MyTag2&lt;/name&gt;
                      &lt;elements&gt;
                          &lt;type&gt;text&lt;/type&gt;
                          &lt;text&gt;12&lt;/text&gt;
                      &lt;/elements&gt;
                  &lt;/elements&gt;
                  &lt;elements&gt;
                      &lt;type&gt;element&lt;/type&gt;
                      &lt;name&gt;tel:MyTag3&lt;/name&gt;
                      &lt;elements&gt;
                          &lt;type&gt;text&lt;/type&gt;
                          &lt;text&gt;MyValue1&lt;/text&gt;
                      &lt;/elements&gt;
                  &lt;/elements&gt;
                  &lt;elements&gt;
                      &lt;type&gt;element&lt;/type&gt;
                      &lt;name&gt;tel:MyTag4&lt;/name&gt;
                      &lt;elements&gt;
                          &lt;type&gt;element&lt;/type&gt;
                          &lt;name&gt;arr:int&lt;/name&gt;
                          &lt;elements&gt;
                              &lt;type&gt;text&lt;/type&gt;
                              &lt;text&gt;1000&lt;/text&gt;
                          &lt;/elements&gt;
                      &lt;/elements&gt;
                      &lt;elements&gt;
                          &lt;type&gt;element&lt;/type&gt;
                          &lt;name&gt;arr:int&lt;/name&gt;
                          &lt;elements&gt;
                              &lt;type&gt;text&lt;/type&gt;
                              &lt;text&gt;1001&lt;/text&gt;
                          &lt;/elements&gt;
                      &lt;/elements&gt;
                      &lt;elements&gt;
                          &lt;type&gt;element&lt;/type&gt;
                          &lt;name&gt;arr:int&lt;/name&gt;
                          &lt;elements&gt;
                              &lt;type&gt;text&lt;/type&gt;
                              &lt;text&gt;1002&lt;/text&gt;
                          &lt;/elements&gt;
                      &lt;/elements&gt;
                  &lt;/elements&gt;
              &lt;/elements&gt;
          &lt;/elements&gt;
      &lt;/elements&gt;
  &lt;/elements&gt;
  </code></pre>
  
  <p>There is a mismatch from input xml and final xml. why this? </p>