Download xml_helper.zip (PHP 5)
$this->load->helper('xml'); $dom = xml_dom(); $book = xml_add_child($dom, 'book'); xml_add_child($book, 'title', 'Hyperion'); $author = xml_add_child($book, 'author', 'Dan Simmons'); xml_add_attribute($author, 'birthdate', '1948-04-04'); xml_print($dom);
Result
<?xml version="1.0"?> <book> <title>Hyperion</title> <author birthdate="1948-04-04">Dan Simmons</author> </book>
xml_dom()
xml_add_child($parent, $name, $value = NULL, $cdata = FALSE)
parent: XML elementname: stringvalue: stringcdata: booleanxml_add_attribute($node, $name, $value = NULL)
node: XML elementname: stringvalue: stringxml_print($dom, $return = FALSE)
dom: XML elementreturn: boolean (if TRUE, just returns XML as a string)