当前位置: 代码迷 >> PHP >> xml加个节点如何写
  详细解决方案

xml加个节点如何写

热度:232   发布时间:2013-03-06 16:20:31.0
xml加个节点怎么写
xml 结构如下

<?xml version="1.0" encoding="utf-8"?>
<note>
</note>



php如下
$note  = simplexml_load_file("a.xml");
$note->appendChild(new DOMElement("time","aaa"));

------解决方案--------------------
PHP在处理XML上有很多扩展,你的代码使用了simplexml类,也使用了DOMElement类,这两个类属于不同的扩展,所以不能用在一起。

提供一个simplexml的示例
$note  = simplexml_load_file("a.xml");
$note->addChild("time","aaa");
file_put_contents('a.xml', $note->asXML());

  相关解决方案