Add elements(nodes) to existing xml file using php
I want to add elements(nodes) to existing xml file. Ex: s I want to add node auth开发者_StackOverflow中文版or tag after title tag .How can write? can i have to use xpath?
Yes, you can.
A little hint: some search results..
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) {
}
精彩评论