PHP and DOMXML

From: Date: Sun, 18 May 2003 03:07:46 +0000
Subject: PHP and DOMXML
Groups: php.general 
Request: Send a blank email to php-general+get-148067@lists.php.net to get a copy of this message
New stuff. First off, Thanks for everyone for their help earlier including "CPT John W. Holmes", and "Daniel Kushner"... So here is my predicament, and if there are any DOMXML experts out their, you may be able to solve my novice question in a heart beat. Im working with a simple xml file <biography><title>title i want to change</title><paragraph>paragraph i want to change</paragraph></bio> All I want to do is pick up some variables from a submitted form with new values for the title and paragraph, such that $_POST[0] = my new title is replaced into the content of that first <title></title> node. Simple enough eh? I would like to accomplish this without doing some kind of search that matches node names because, as the $filelocation shows, i am going to use this script on several different xml files, each with the same structure but perhaps different node names. I am currently getting an error on line 11 saying that there was a call to a member function on a non-object --- this is the line that says $textnode->set_content($POST[$a]); I tried moving this set_content() function up to the line above $tobeupdated[$a] and there is no longer any error but the dump_mem() reveals the ORIGINAL xml file with nothing updated at all... Any help? Do I need to scrap this method and use create_element() append_child() somehow, and if so how? :-( It used to be soooo easy add_child('node name','node content'); brilliantly easy. <? $filelocation = 'xml/' . $_GET["idnum"] . '.' . $_GET["type"] . '.xml'; $xmlDoc =& domxml_open_file($filelocation); $root =& $xmlDoc->document_element(); $tobeupdated =& $root->children(); for($a=0; $a<sizeof($tobeupdated); $a++) { $textnode =& $tobeupdated[$a]->first_child(); $textnode->set_content($_POST[$a]); } echo $xmlDoc->dump_mem(); $xmlDoc->dump_file($filelocation, false, false); ?> Thanks for any help!

« previous php.general (#148067) next »