| 2 comments ]

Inserting nodes into xml files using XML DOM in PHP .

//creating the dom object
$dom = new DOMDocument();
$dom->formatOutput = true;

//loading the existing XML file
$dom->load('example.xml');

//writting new xml node

$rootnode = $dom->getElementsByTagName("details")->item(0);

$root=$dom->createElement("inner");

$firstnameVal = $dom->createElement("firstname,$firstname);
$lastnameVal = $dom->createElement("lastname",$lastname);
$description = $dom->createElement("description", $description);

$root->appendChild($firstnameVal);
$root->appendChild($lastnameVal);
$root->appendChild($description);

$rootnode->appendChild($root);

$dom->appendChild($rootnode);

//saving the new node into the existing xml file
$dom->save(''example.xml');

Output the XML FILE

<details>
<inner>
<firstname>AP</firstname>
<lastname>John</lastname>
<description>programmer</description>
</inner>
<inner>
<firstname>KH</firstname>
<lastname>Samuel</lastname>
<description>programmer</description>
</inner>
<inner>
<firstname>KH</firstname>
<lastname>Samuel</lastname>
<description>programmer</description>
</inner>
</details>

2 comments

jj said... @ Friday, March 13, 2009 at 7:52:00 AM GMT

http://phpqa.blogspot.com/2009/02/jquery-based-dynamic-adding-and-removal.html

visit this 4 juery based functionality

jj said... @ Friday, March 13, 2009 at 7:53:00 AM GMT

http://phpqa.blogspot.com/2009/02/jquery-based-dynamic-adding-and-removal.html

based o0n jqeury

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.