title: Create XML from HTML and add to existing XML table
body: <p>So in Drupal i am looking to create an XML form using code for each node. I have successfully created an XML table using the following code...</p>
  
  <pre><code>$xml = new DOMDocument("1.0", "utf-8");
  $root = $xml-&gt;createElement("article");
  $xml-&gt;appendChild($root);
  $front = $xml-&gt;createElement("front");
  $root-&gt;appendChild($front);
  $journal_meta = $xml-&gt;createElement("journal-meta");
  $front-&gt;appendChild($journal_meta);
  $journal_id = $xml-&gt;createTextNode($form['#node']-&gt;field_journal_id['und'][0]['value']);
  $journal_meta-&gt;appendChild($journal_id);
  
  $xml-&gt;formatOutput = true;
  echo "&lt;xmp&gt;". $xml-&gt;saveXML() ."&lt;/xmp&gt;";
  $xml-&gt;save("mybooks.xml") or die("Error");
  
  OUTPUT:
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;article&gt;
    &lt;front&gt;
      &lt;journal-meta&gt;en&lt;/journal-meta&gt;
    &lt;/front&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>Now i also want to load the body field which includes HTML and add this to the XML table output above. I have managed to load the body field into a domDocument and then specifically targeted the body tag to create the node list.</p>
  
  <p>What i have not been able to do is iterate over the node list, and all all the elements and appendchilds on my original $xml variable.</p>
  
  <pre><code>$body = $form['#node']-&gt;body['und'][0]['value'];
  $tidy = tidy_parse_string($body);
  $body = $tidy-&gt;body();
  $dom = new DomDocument();
  $dom-&gt;loadHTML('&lt;?xml encoding="UTF-8"&gt;' . $body);
  
  print_r($dom-&gt;saveHTML());
  $div = $dom-&gt;getElementsByTagName('body');
  </code></pre>
  
  <p>The $dom variable contains the domDocument and $div variable contains the Nodelist, how can this be done to create one XML document without using Cdata?</p>