appendChild() something I fail to understand
Brought to you by:
bs_php,
nigelswinson
From: Luc Saint-E. <lu...@sa...> - 2002-01-17 08:01:41
|
Hello all, To learn how to produce (and no more how to read) XML files from xpath.class.php, I'm writing some kind of little instant messenger system. My first goal is too have each new connected user added in a connectes.xml file the file is very simple <connectes> <user name="theuserloginname" intime="timeofarrival"> </connectes> Login name is known and timeofarrival is a simple time() Here is an abstract of my code (part of a switch) -------------------------- default : // display connected user listing $xPath->reset(); $connecte = array(); $xPath->importFromFile('xml_files/connectes.xml'); $aResult = $xPath->evaluate('/connectes/user'); foreach ( $aResult as $user ) { $t = $xPath->getAttributes($user); array_push ($connecte, array('name' =>$t['name'])); } // Add curent user to this list $xPath->appendChild('/connectes[1]', 'user'); $attributes['name'] = $user_name; $attributes['intime'] = time(); $xPath->setAttributes('/connectes[1]/user[1]', $attributes); $xPath->exportToFile('xml_files/connectes.xml','','<?xml version="1.0" encoding="iso-8859-1"'.'?'.'>'); $is_connected = 'oui'; $session_register("is_connected"); At the firdst invocation every thing goes fine But if I open another browser (to simulate twoi user I use netscape for one and MIE for the other) the seond user is added to my connectd.xml file but the first one is emptied here is the file Step one : no one is connected ======================== <?xml version="1.0" encoding="iso-8859-1"?> <connectes/> Step two first user connected ======================== <?xml version="1.0" encoding="iso-8859-1"?> <connectes> <user name="user1" intime="1011253765"/> </connectes> Step three a second user is connected =============================== <?xml version="1.0" encoding="iso-8859-1"?> <connectes> <user name="user2" intime="1011253789"/> <user/> </connectes> As you can see the second user is added to the file.. but the first is emptied. Where did I screw up ??? Any idea ? Luc |