replacechild help`!!!! `Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
punnathee
Forum Newbie
Posts: 1
Joined: Sat Mar 27, 2004 1:23 pm

replacechild help`!!!! `Please

Post by punnathee »

`please check my code I'm newbie for php5 and xml


"friends.xml"
<?xml version="1.0" encoding="UTF-8"?>
<friends>
<friend>
<name>Eric</name>
<email>eric@hotmail.com</email>
</friend>

<friend>
<name>John</name>
<email>john@hotmail.com</email>
</friend>


<friend>
<name>James</name>
<email>james@hotmail.com</email>
</friend>
</friends>



friends.php


<?php

#- The path to the XML files
$dom = new DomDocument();
$dom->load("friends.xml");


$xp = new domxpath($dom);
$result = $xp->query("//friends/friend[name =
'James']/email");
#- Get the node

$email = $result->nodeset;
//#- Create the new email and replace the old one
$newEmail = $dom->createtextnode('jamesnew@hotmail.com');
$email[0]->replacechild( $newEmail,
$email[0]->first_child());


#- Print it as an XML file
print $dom->save("friends.xml");

?>



please show me some sample of replacechild replacenode
!!!!!

best regard

thee
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Post Reply