PHP如何写XML文件?
已有一个XML文件,代码如下:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?xml version="1.0" encoding="GB2312"?><appconfig> <com>COM1</com> <phone>10086</phone> <content>测试</content></appconfig>
$phone=123;$xmlDoc = new DOMDocument();$xmlDoc->load("bb.xml");$xml = new SimpleXMLElement($xmlDoc->saveXML());$xml->Phone = $phone;file_put_contents('bb.xml', $xml->asXML());<br><font color="#e78608">------解决方案--------------------</font><br>
<?php $xml = new DOMDocument("1.0","GB2312");//实例化domdocument类$xml->load('test3.xml');//加载xml文件$list=$xml->getElementsByTagName('Phone');$phone='iphone';$list->item(0)->nodeValue=$phone; $xml->save("test3.xml");//保存?><br><font color="#e78608">------解决方案--------------------</font><br>
<?phprequire_once ("xmlparse.php"); $xml = new DOMDocument("1.0","GB2312");$xml->load("你的xml的路径");$list=$xml->getElementsByTagName('Phone');$list->item(0)->nodeValue=$phone; $xml->save("你的xml的路径");//保存?><div class="clear"> </div>