PHP4 & XML Generation

Posted by Quinn Madson | Posted in | Posted on 8:31 AM

0

<?php
// generate xml mime type
header ("content-type: text/xml");

// create xml document
$doc = domxml_new_doc('1.0');

// create xml root
$root = $doc->create_element("xml_root");
$root = $doc->append_child($root);

// create xml node
$item = $doc->create_element("xml_item");
$item = $root->append_child($item);

// add some text to the node
$item_text = $doc->create_text_node("yo yo");
$item = $item->append_child($item_text);

// generate xml output
$xml_string = $doc->dump_mem(true);
echo $xml_string;
?>
would generate:

<?xml version="1.0"?>
<xml_root>
<xml_item>yo yo</xml_item>
</xml_root>

Comments (0)