用 PHP5 轻松解析 XML(5)

                 foreach($tmpIds as $tkey=>$tid)
                 {
                     if(strpos($key, $name)==0)
                     {
                         $id = $tid;
                         break;
                     }
                 }
             }
             return $rootNodeObj->getNodeById($id);
         }
     }

     public function findNodeByPath($path)
     {
         $pos = strpos($path, '|');
         if($pos<=0)
         {
             return $this->getNode($path);


         }
         else
         {

             $tmpObj = $this->getNode(substr($path, 0,
             $pos));

             return is_object($tmpObj)?
             $tmpObj->findNodeByPath(substr($path,
             $pos+1)):
             null;
         }
     }

     public function getSaveData()
     {
         $data = $this->values;
         if(sizeof($this->attributes)>0)

         $data[attrs] = $this->attributes;
         $nodeList = $this->getNode();


         if($nodeList==null)

         return $data;
         foreach($nodeList as $key=>$node)
         {
             $data[$key] = $node->getSaveData();
         }

         return $data;
     }


     public function getSaveXml($level=0)
     {

         $prefixSpace
         = str_pad("",
         $level, "\t");
         $str = "$prefixSpace<$this->nodeTag";

 

         foreach($this->attributes as $key=>$value)
         $str .= " $key=\"$value\"";

         $str .= ">\r\n";


         foreach($this->values as $key=>$value){

             if(is_array($value))
             {
                 $str .= "$prefixSpace\t<$key";

                 foreach($value[attrs] as $attkey=>$attvalue)

                 $str .= " $attkey=\"$attvalue\"";

                 $tmpStr = $value[value];


             }
             else

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3453d9ab26a2444cbe11eab65ea43358.html