Thread: appendChild help?
Brought to you by:
bs_php,
nigelswinson
From: Paul / U. <pa...@tr...> - 2001-11-06 11:23:25
|
I'm using Php.XPath Version 2.1 and I'm having some trouble understanding what to pass into appendChild as the node. Could someone give me a simple example of appending a child to a node. e.g. file contents are <root></root> $xml = new XPath("$filename"); $xml->appendData("/root[1]", "blah" ); What do I put in instead of "blah" to add a node called blah? Paul www.nostalgiagoggles.com |
From: Girish N. <gi...@bt...> - 2001-11-06 11:44:24
|
Hi I've been trying to figure this out too. The only way can do it is to appendChild() then appendData() into that child. $xml->appendChild("/root[1]", "newchild"); $xml->appendData("/root[1]/newchild[1]", "some new data here"); It would be nice to be able to to this in one step. Any help appreciated. Girish ----- Original Message ----- From: "Paul / USH" <pa...@tr...> To: <php...@li...> Sent: Tuesday, November 06, 2001 11:19 AM Subject: appendChild help? > I'm using Php.XPath Version 2.1 and I'm having some trouble understanding what to pass into appendChild as the node. > > Could someone give me a simple example of appending a child to a node. > > e.g. > > file contents are <root></root> > $xml = new XPath("$filename"); > $xml->appendData("/root[1]", "blah" ); > > What do I put in instead of "blah" to add a node called blah? > > Paul > www.nostalgiagoggles.com > > > > _______________________________________________ > Phpxpath-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpxpath-users |
From: Nigel S. <nig...@us...> - 2001-11-06 14:03:58
|
> Could someone give me a simple example of appending a child to a node. > > e.g. > > file contents are <root></root> > $xml = new XPath("$filename"); > $xml->appendData("/root[1]", "blah" ); > > What do I put in instead of "blah" to add a node called blah? Erm, that should work. You should get: <root><blah/></root> Don't you? How do you know you don't? Perhaps mail round example xml file and php script? > I've been trying to figure this out too. The only way can do it is to > appendChild() then appendData() into that child. > > $xml->appendChild("/root[1]", "newchild"); > $xml->appendData("/root[1]/newchild[1]", "some new data here"); > > It would be nice to be able to to this in one step. > > Any help appreciated. It's on it's way. Soon you'll be able to do: appendChild("/root[1]","<newchild>some new data here</newchild>"); Nigel =========================== For the most recent version of Php.XPath, V2.x, and an archive of this list visit: http://www.sourceforge.net/projects/phpxpath |
From: Paul / U. <pa...@tr...> - 2001-11-06 14:30:58
|
On 06 Nov 2001 11:41 GMT you wrote: > Hi > > I've been trying to figure this out too. The only way can do it is to > appendChild() then appendData() into that child. > > $xml->appendChild("/root[1]", "newchild"); > $xml->appendData("/root[1]/newchild[1]", "some new data here"); Thankyou, you've just solved my initial problem I was using appendData - when I should have been using appendChild first. Paul www.nostalgiagoggles.com > > It would be nice to be able to to this in one step. > > Any help appreciated. > > > Girish > > ----- Original Message ----- > From: "Paul / USH" <pa...@tr...> > To: <php...@li...> > Sent: Tuesday, November 06, 2001 11:19 AM > Subject: appendChild help? > > > > I'm using Php.XPath Version 2.1 and I'm having some trouble understanding > what to pass into appendChild as the node. > > > > Could someone give me a simple example of appending a child to a node. > > > > e.g. > > > > file contents are <root></root> > > $xml = new XPath("$filename"); > > $xml->appendData("/root[1]", "blah" ); > > > > What do I put in instead of "blah" to add a node called blah? > > > > Paul > > www.nostalgiagoggles.com |
From: Dan A. <big...@us...> - 2001-11-06 17:35:49
|
Remember, appendChild returns the absolute path (aka /root[1]/newchild[1]) so that you don't have to figure it out manually after adding the new child. so you can do $newnode = $xml->appendChild("/root[1]","newchild"); $xml->appendData($newnode,"data); Dan On Tue, 06 Nov 2001 14:26:49 GMT Paul / USH <pa...@tr...> wrote: > On 06 Nov 2001 11:41 GMT you wrote: > > > Hi > > > > I've been trying to figure this out too. The only way can do it is to > > appendChild() then appendData() into that child. > > > > $xml->appendChild("/root[1]", "newchild"); > > $xml->appendData("/root[1]/newchild[1]", "some new data here"); > > Thankyou, you've just solved my initial problem > I was using appendData - when I should have been using appendChild first. > > Paul > www.nostalgiagoggles.com > > > > > > It would be nice to be able to to this in one step. > > > > Any help appreciated. > > > > > > Girish > > > > ----- Original Message ----- > > From: "Paul / USH" <pa...@tr...> > > To: <php...@li...> > > Sent: Tuesday, November 06, 2001 11:19 AM > > Subject: appendChild help? > > > > > > > I'm using Php.XPath Version 2.1 and I'm having some trouble understanding > > what to pass into appendChild as the node. > > > > > > Could someone give me a simple example of appending a child to a node. > > > > > > e.g. > > > > > > file contents are <root></root> > > > $xml = new XPath("$filename"); > > > $xml->appendData("/root[1]", "blah" ); > > > > > > What do I put in instead of "blah" to add a node called blah? > > > > > > Paul > > > www.nostalgiagoggles.com > > > _______________________________________________ > Phpxpath-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpxpath-users |
From: Luc Saint-E. <lu...@sa...> - 2002-01-16 14:12:33
|
Hello, I've been using phpxml the xpath.class.php but only to read wml file. Now I need to use it to add stuff in a xml file and I fail The file is very basic: <connectes> <user name="fooname" intime="footime"/> <user name="fooname1" intime="footime2"/> etc... </connectes> Doing : require_once 'lib/XPath.class.php'; $xPath = new XPath(); $attributes = array(); $xPath->reset(); $xPath->importFromFile('xml_files/connectes.xml'); $xPath->appendChild('/connectes[1]', 'user'); $attributes['name'] = $user_name; // => $user_name is a session variable $attributes['intime'] = time(); $xPath->setAttributes('/connectes[1]/user[1]', $attributes); Nothing happen, I get no error but the xml file is left untouched Luc |
From: Nigel S. <nig...@us...> - 2002-01-16 14:19:36
|
> I've been using phpxml the xpath.class.php but only to read wml file. > > Now I need to use it to add stuff in a xml file and I fail > > The file is very basic: > <connectes> > <user name="fooname" intime="footime"/> > <user name="fooname1" intime="footime2"/> > etc... > </connectes> > > Doing : > > > require_once 'lib/XPath.class.php'; > $xPath = new XPath(); > $attributes = array(); > $xPath->reset(); > $xPath->importFromFile('xml_files/connectes.xml'); > $xPath->appendChild('/connectes[1]', 'user'); > $attributes['name'] = $user_name; // => $user_name is a session variable > $attributes['intime'] = time(); > $xPath->setAttributes('/connectes[1]/user[1]', $attributes); > > Nothing happen, I get no error but the xml file is left untouched Are you doing a ->exportToFile($filename)? If you don't export, then changes will not persist to disk. Nigel |
From: Luc Saint-E. <lu...@sa...> - 2002-01-16 15:23:29
|
Nigel, In fact I had to ad : $xPath->setAttribute('/am/i/stupid[1]', 'yes'); Luc At 14:18 16/01/02 +0000, Nigel Swinson wrote: > > I've been using phpxml the xpath.class.php but only to read wml file. > > > > Now I need to use it to add stuff in a xml file and I fail > > > > The file is very basic: > > <connectes> > > <user name="fooname" intime="footime"/> > > <user name="fooname1" intime="footime2"/> > > etc... > > </connectes> > > > > Doing : > > > > > > require_once 'lib/XPath.class.php'; > > $xPath = new XPath(); > > $attributes = array(); > > $xPath->reset(); > > $xPath->importFromFile('xml_files/connectes.xml'); > > $xPath->appendChild('/connectes[1]', 'user'); > > $attributes['name'] = $user_name; // => $user_name is a session variable > > $attributes['intime'] = time(); > > $xPath->setAttributes('/connectes[1]/user[1]', $attributes); > > > > Nothing happen, I get no error but the xml file is left untouched > >Are you doing a ->exportToFile($filename)? If you don't export, then >changes will not persist to disk. > >Nigel > > > >_______________________________________________ >Phpxpath-users mailing list >Php...@li... >https://lists.sourceforge.net/lists/listinfo/phpxpath-users |