假如有下面xml文件:
<span style="font-family:SimSun;"><?xml version="1.0" encoding="UTF-8"?> <setting> <setting1>setting1 value</setting1> <setting2>setting2 value</setting2> <setting3>setting3 value</setting3> .... .... .... </setting></span>
// CREATE $config = new SimpleXmlElement('<settings/>'); $config->setting1 = 'setting1 value'; $config->saveXML('config.xml'); // READ $config = new SimpleXmlElement('config.xml'); echo $config->setting1; echo $config->asXml(); // UPDATE $config->setting1 = 'new value'; $config->setting2 = 'setting2 value'; echo $config->asXml(); // DELETE unset($config->setting1); $config->setting2 = NULL; echo $config->asXML(); unlink('config.xml');
原文地址:http://blog.csdn.net/xiebaochun/article/details/38893469