domxml->dump_file

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

domxml->dump_file

Post by kendall »

hi,

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';
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
Post Reply