title: how to generate XML with soap envelope and body tag using php
body: <p>I'm unable to generate XMl with Soap Envelop and Body Tag, here is the code,</p>
  
  <pre><code>$rootElement  = $XMLDoc-&gt;createElement('AddDetails');
          $rootNode = $XMLDoc-&gt;appendChild($rootElement);
  
          while($result_array =  $result-&gt;fetch_assoc())  {
              $StockCount++;
                foreach($result_array as $key =&gt; $value)  {
                    $value=trim($value);
                    if($value=="NULL" || $value=="" ||$value==-1){
                          $value="";
                    }
                      $value=htmlentities($value);//For validating &amp; chars
                      $rootNode-&gt;appendChild($XMLDoc-&gt;createElement($key,$value));
                }
             }
  </code></pre>
  
  <p>The above code resulting XMl with Key and values like </p>
  
  <pre><code>&lt;AddDetails&gt;
  &lt;First_Name&gt;TestFName&lt;/First_Name&gt;
  &lt;Last_Name&gt;TestLName&lt;/Last_Name&gt;
  &lt;/AddDetails&gt;
  </code></pre>
  
  <p>but i want to generate XML like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soap:Body&gt;
  &lt;AddDetails xmlns="http://tempuri.org/"&gt;
  &lt;First_Name&gt;TestFName&lt;/First_Name&gt;
  &lt;Last_Name&gt;TestLName&lt;/Last_Name&gt;
  &lt;/AddDetails&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Please help me.</p>