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...
$xml = new DOMDocument("1.0", "utf-8");
$root = $xml->createElement("article");
$xml->appendChild($root);
$front = $xml->createElement("front");
$root->appendChild($front);
$journal_meta = $xml->createElement("journal-meta");
$front->appendChild($journal_meta);
$journal_id = $xml->createTextNode($form['#node']->field_journal_id['und'][0]['value']);
$journal_meta->appendChild($journal_id);
$xml->formatOutput = true;
echo "<xmp>". $xml->saveXML() ."</xmp>";
$xml->save("mybooks.xml") or die("Error");
OUTPUT:
<?xml version="1.0" encoding="utf-8"?>
<article>
<front>
<journal-meta>en</journal-meta>
</front>
</article>
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.
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.
$body = $form['#node']->body['und'][0]['value'];
$tidy = tidy_parse_string($body);
$body = $tidy->body();
$dom = new DomDocument();
$dom->loadHTML('<?xml encoding="UTF-8">' . $body);
print_r($dom->saveHTML());
$div = $dom->getElementsByTagName('body');
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?
this is some test content
more test content
– Key Jun 10 '14 at 15:14