Hi I want to add elements(nodes) to existing xml file. Ex: s I want to add node author tag after title tag .How can write? can i have to use xpath?
+1
A:
Hi, Load your xml from string(doc) or a file(doc) using SimpleXML.
$xml = simplexml_load_file('file.xml');
$xml = simplexml_load_string($string);
$xml = new SimpleXMLElement($string);
Then use addChild method of SimpleXML to insert node at particular point http://www.php.net/manual/en/simplexmlelement.addChild.php.
Edited: You can loop through nodes using SimpleXML children() method http://www.php.net/manual/en/simplexmlelement.children.php
foreach ($xml->children() as $children) {
}
Ayaz Alavi
2010-08-25 11:40:16