PHP4 XML DOM - write to document
Posted: Wed Feb 07, 2007 11:00 am
I am trying to write a php script which adds an element tagged ‘log’ to the root element ‘newletter_log’. I want it to have attributes added which are passed on via parameter variables from the function. I originally wrote the script for php5, however, I now need it to work in a php4 environment. My original script was:
This doesn’t work with php4. How can I convert the code to php4? Also, how can I find out if the host has DOMXML enabled?
Code: Select all
$xml_dom = new DOMDocument(); // Load DOM Object
$xml_dom -> load('db.xml'); // Load xml databse into the object
$newsletter_log = $xml_dom -> getElementsByTagName('newsletter_log')->item(0); // Asign the element to a vaible
$newElement = $xml_dom -> createElement('log'); // Create a new elemnt and asign to varible
$newsletter_log -> appendChild($newElement); // Apend the new element node into the parent element
$newElement -> setAttribute('action', $act); // Setting new atriubts to the element
$newElement -> setAttribute('email', $email);
$newElement -> setAttribute('time/date', date("H:i d.m.y"));
$newElement -> setAttribute('recommended',$recommended);
$xml_dom -> save("db.xml");