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>
Showing posts with label Creating xml files using XML DOM in PHP. Show all posts
Showing posts with label Creating xml files using XML DOM in PHP. Show all posts
[Wednesday, October 17, 2007
|
2
comments
]
Popular Posts
- Elgg : The most popular open source social networking platform
- some php questions
- function to check whether the year given is a leap year or not
- php Questions
- Running a perl script from PHP
- Jquery based dynamic adding and removal of html elements.
- php questions
- function to validate the a given credit card based on the card type and based on luhns algorithm
- Mysql query for searching a value, add weightage on the number of occurances and sort based on the weight-age
- Help with codeignitor