title: PHP XML How to create Nested Node?
body: <p>I use php <code>DOMDocument</code> to create and save <code>XML</code> file.
  here is my code</p>
  
  <pre><code>$doc = new DOMDocument();
  $document = $doc-&gt;createElement('DOCUMENT');
  $document-&gt;nodeValue = '';
  $doc-&gt;appendChild($document);
  
  $order = $doc-&gt;createElement('ORDER');
  $order-&gt;nodeValue = '';
  $doc-&gt;appendChild($order);
  
  $ele = $doc-&gt;createElement('Reportvariable1');
  $ele-&gt;nodeValue = '';
  $doc-&gt;appendChild($ele);
  
  $ele = $doc-&gt;createElement('Reportvariable1');
  $ele-&gt;nodeValue = '';
  $doc-&gt;appendChild($ele);
  
  $ele = $doc-&gt;createElement('Reportvariable1');
  $ele-&gt;nodeValue = '';
  $doc-&gt;appendChild($ele);
  
  $ele = $doc-&gt;createElement('Reportvariable1');
  $ele-&gt;nodeValue = '';
  $doc-&gt;appendChild($ele);
  
  $doc-&gt;appendChild($ele);
  $doc-&gt;save('order_xml/Order_.xml');
  </code></pre>
  
  <p>its Output is simple like this : </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;DOCUMENT&gt;&lt;/DOCUMENT&gt;
  &lt;ORDER&gt;&lt;/ORDER&gt;
  &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
  &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
  &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
  &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
  </code></pre>
  
  <p>How do I create nested nodes like this ?</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;DOCUMENT&gt;
      &lt;ORDER&gt;
         &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
         &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
         &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
         &lt;Reportvariable1&gt;&lt;/Reportvariable1&gt;
     &lt;/ORDER&gt;
  &lt;/DOCUMENT&gt;
  </code></pre>