开发者

how to write into existing xml file using php

Hi every one I have an XML file, it's contain same tags like this:

<data>
<info><detail>first data</detail></info>
<info><detail>second data</detail></info>
<info><detail>third data</detail></info>
....
</data>

I want to add this:

<info><detail>fourth data</detail></info>

to my file.

and thanks for any hel开发者_如何学Cp.


$xml = simplexml_load_file('foo.xml');
$xml->addChild('info')->addChild('detail', 'fourth data');
file_put_contents('foo.xml', $xml->asXML());


Look into the simplexml extension for PHP

http://us3.php.net/simplexml

Specifically http://us3.php.net/manual/en/simplexmlelement.addchild.php for adding the node once you have created it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜