开发者

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) {
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜