domxml->dump_file
Posted: Mon Nov 07, 2005 5:04 pm
hi,
i am building a php process that updates an xml file using the domxml functions.
but my if statment echos the fail string.
some how i think i am not appending the nodes right can someone see where i am wrong?
Kendall
i am building a php process that updates an xml file using the domxml functions.
Code: Select all
// update XML tree
// set file
define('XML_FILE',"sample_tree.xml");
// load the file
if (!$dom = domxml_open_file(XML_FILE,DOMXML_LOAD_PARSING,$error)) {
echo "Error while parsing the document\n";
exit;
}
// get the root
$xmlRoot = $dom->document_element();
// create a new branch
$branch = $dom->create_element("branch");
$new_branch = $xmlRoot->append_child($branch); // append new branch to tree
// set branch attributes
$new_branch->set_attribute("id",$PID);
$new_branch->set_attribute("refid",$ID);
$new_branch->set_attribute("name",$name);
$new_branch->set_attribute("age",$age);
$new_branch->set_attribute("location",$name);
// create comments node
$comments = $dom->create_element("comments");
$comments_text = $dom->create_text_node($comment);
$tcomments = $comments->append_child($comments_text); // append text to node
$new_branch = $new_branch->append_child($tcomments); // append node
// append branch to xml tree
$xmlRoot->append_child($new_branch);
// generate new xml file
if($dom->dump_file("/home/virtual/site1/fst/var/www/html/ncc_aids/sample_tree.xml", true)<=0)
echo 'ok';
else echo 'fail';some how i think i am not appending the nodes right can someone see where i am wrong?
Kendall