首页 >php教程 >php手册 >使用PHP 5.0 轻松解析XML文档(6)

使用PHP 5.0 轻松解析XML文档(6)

WBOY
WBOY原创
2016-05-26 08:19:331006浏览

下面是通过createNode()函数,添加商品, 然后显示添加后的结果

<?xml version="1.0" encoding="GB2312" ?>
<shop>
<name>华联</name>
<address>北京长安街-9999号</address>
<desc>连锁超市</desc>
<telphone>123456789</telphone>
<cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food12">
   <name>new food12</name>
   <price>22.10</price>
  </goods>
  <goods id="food13">
   <name>food13</name>
   <price>100</price>
  </goods>
</cat>
<cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
</cat>
<cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
</cat>
<special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
</special>
</shop>
下面是通过removeNode()函数,删除商品, 然后显示删除后的结果
<?xml version="1.0" encoding="GB2312" ?>
<shop>
<name>华联</name>
<address>北京长安街-9999号</address>
<desc>连锁超市</desc>
<telphone>123456789</telphone>
<cat id="food">
  <goods id="food11">
   <name>food11</name>
   <price>12.90</price>
   <leaveword author="hahawen" date="2004-12-05">这个商品不错</leaveword>
  </goods>
  <goods id="food13">
   <name>food13</name>
   <price>100</price>
  </goods>
</cat>
<cat>
  <goods id="tel21">
   <name>tel21</name>
   <price>1290</price>
  </goods>
</cat>
<cat id="coat">
  <goods id="coat31">
   <name>coat31</name>
   <price>112</price>
  </goods>
  <goods id="coat32">
   <name>coat32</name>
   <price>45</price>
  </goods>
</cat>
<special id="hot">
  <goods>
   <name>hot41</name>
   <price>99</price>
  </goods>
</special>
</shop>


本文地址:

转载随意,但请附上文章地址:-)

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn