The following example illustrates the operation of the DOM on XML in a nutshell, see the comments in the code for a detailed explanation
<? /************************************************ * * Use XML in PHP5 * * Reference site: * * http://cn.php.net/manual/zh/ ref.dom.php * * The follow codes need PHP5 support *************************************************/// First, you create a DomDocument object $dom = new DomDocument (); Then load the XML file $dom-load ("Test.xml"); Output XML file//header ("content-type:text/xml;charset=gb2312"); Echo $dom-SaveXML (); Save the XML file with a return value of int (file size, in bytes)//$dom Save ("Newfile.xml"); echo "
The following is the Test.xml file code:
<?xml version= "1.0" encoding= "gb2312"?> <rss version= "2.0" > <channel> <title>javascript</ Title> <link>http://blog.csdn.net/zhongmao/category/29515.aspx</link> <description> javascript</description> <language>zh-chs</language> <generator>.text Version 0.958.2004.2001</generator> <item> <creator>zhongmao</creator> <title orderby= "1" > Out put Excel used javascript</title> <link>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385. Aspx</link> <pubdate>wed, Sep 2004 13:32:00 gmt</pubdate> <guid>http://blog.csdn.net/ Zhongmao/archive/2004/09/15/105385.aspx</guid> <comment>http://blog.csdn.net/zhongmao/comments/ 105385.aspx</comment> <comments>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx# Feedback</comments> <comments>2</comments> <commentrss>http://blog.csdn.net/zhongmao/ Comments/commentrss/105385.aspx</commentrss> <ping>http://blog.csdn.net/zhongmao/services/trackbacks/105385.aspx</ ping> <description>test description</description> </item> <item> <creator>zhongmao </creator> <title orderby= "2" >out put word used javascript</title> <link>http://blog.csdn.net /zhongmao/archive/2004/08/06/67161.aspx</link> <pubdate>fri, 2004 16:33:00 gmt</pubdate> <guid>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx</guid> <comment>http:// Blog.csdn.net/zhongmao/comments/67161.aspx</comment> <comments>http://blog.csdn.net/zhongmao/ Archive/2004/08/06/67161.aspx#feedback</comments><comments>0</comments> <commentrss> Http://blog.csdn.net/zhongmao/comments/commentrss/67161.aspx</commentrss> <ping>http:// blog.csdn.net/zhongmao/services/trackbacks/67161.aspx</ping> <description>test Word description</ Description> </item> <item> <creator>zhongmao</creator> <title orderby= "3" >xmlhttp</title> <link>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</link> <pubdate>mon, Geneva 2004 10:11:00 Gmt</pubdate> <guid>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</ Guid> <comment>http://blog.csdn.net/zhongmao/comments/58417.aspx</comment> <comments>http:/ /blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx#feedback</comments><comments>0</comments > <commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/58417.aspx</commentrss> <ping >http://blog.csdn.net/zhongmao/services/trackbacks/58417.aspx</ping> <description>xmlhttpaaa ASD bb cc dd</description> </item> </channel> </rss>
The above is PHP5 in the use of DOM Control XML implementation Code _php tutorial content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!