php读写xml基于DOMDocument方法
1.读xml内容: xml文件plays.xml文档结构: <?xml version="1.0" encoding="UTF-8"?> <Plays> <play> <title id="001">rabits</title> <author>tom</author> <date>2015.1.2</date> <addr>Beijing Fengtai Juyuan</addr> </play> <play> <title id="002">Mom's Love</title> <author>Jim</author> <date>2015.4.5</date> <addr>Beijing haiding Juyuan</addr> </play> </Plays> php xml文档读操作: <?php $doc = new DOMDocument(); $doc->load("plays.xml"); $plays = $doc->getElementsByTagName("play"); /** * xml文档读取 */ echo '<strong style="color:red">文档读取:</strong><br>'; foreach( $plays as $play ) { $titles = $play->getElementsByTagName("title"