2008年我们一起努力~Oh,YES!

读取修改XML文档

上一篇 / 下一篇  2008-04-14 10:03:18

<?xml version="1.0" encoding="UTF-8"?>
<pie>
  <!--
  <message bg_color="#CCBB00" text_color="#FFFFFF">
    <![CDATA[You can broadcast any message to chart from data XML file]]>
  </message>
  -->
  <slice title="服务器1" pull_out="true" descrīption="4026小时41分钟">14496075</slice>
  <slice title="默认天数" descrīption="360小时19分钟">1297151</slice>
  <slice title="Never" url="http://www.interactivemaps.org" descrīption="Click on the slice to find more information" alpha="50">0</slice>
</pie>

    $doc = new DOMDocument();
    $doc->load('ampie/ampie_data.xml');

    //查找 pie 节点
    $root = $doc->getElementsByTagName('pie');

    //第一个 pie 节点
    $root = $root->item(0);

    //查找 pie 节点下的 slice 节点
    $slice = $root->getElementsByTagName('slice');

    //遍历所有 slice 节点
    foreach ($slice as $rootdata)
    {
     foreach ($rootdata->attributes as $attrib)
      {
       $attribName = $attrib->nodeName; //nodeName为属性名称
       $attribValue = $attrib->nodeValue; //nodeValue为属性内容

       //查找属性名称为ip的节点内容
       if ($attribName =='title')
       {
        if (iconv("UTF-8","gb2312",$attribValue)==$server_array[$i]["name"])
        {
         //修改文本
         $tatoltime=floor($SUMTimeLengthALL/3600)."小时".date ("i分钟",$SUMTimeLengthALL);
         $rootdata->setAttribute('descrīption',iconv("gb2312","UTF-8",$tatoltime));
         $rootdata->nodeValue=$SUMTimeLengthALL;
        }
        if (iconv("UTF-8","gb2312",$attribValue)=="默认天数")
        {
         //另一个部分默认天数         
         $parttime1=floor($SUMTimeLength/3600)."小时".date ("i分钟",$SUMTimeLength);
         $rootdata->setAttribute('descrīption',iconv("gb2312","UTF-8",$parttime1));
         $rootdata->nodeValue=$SUMTimeLength;
        }         
        $doc->save('ampie/ampie_data.xml');
       }
      }
    }


TAG: php xml

引用 删除 Guest   /   2008-05-25 22:58:18
http://blog.csdn.net/fdy1txz/ 小说社区
http://www.jipinjiading36.cn   极品家丁
http://www.meinv880.cn 我的美女大小姐
http://column.iresearch.cn/u/fdytxz/ 小冯的专栏
http://www.xingchenbian33.cn 坏蛋是怎样炼成的
http://column.iresearch.cn/u/fdy2txz/ 心情驿站
http://blog.csdn.net/fdy2txz/ 流动的小说站
http://www.5pr5.cn 极品公子
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar