tags:

views:

15

answers:

2

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?

A: 

Yes, you can.

A little hint: some search results..

Ben Fransen
+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