用 PHP5 轻松解析 XML(4)

     public function setValue($name, $value)
     {
         $this->values[$name] = $value;
     }

     public function getValue($name=null)
     {
         return $name==null?
         $this->values: $this->values[$name];
     }

 

     public function removeValue($name)
     {
         unset($this->values["$name"]);
     }

     public function setAttributes($attributes){
         $this->attributes = $attributes;
     }

     public function setAttribute($name, $value)
     {
         $this->attributes[$name] = $value;
     }

     public function getAttribute($name=null)
     {
         return $name==null? $this->attributes:
         $this->attributes[$name];
     }

     public function removeAttribute($name)
     {
         unset($this->attributes["$name"]);
     }

     public function getNodesSize()
     {
         return sizeof($this->nodes);
     }

     protected function setNode($name, $nodeId)
     {
         $this->nodes[$name]
         = $nodeId;
     }

     public abstract function createNode($name, $attributes);

     public abstract function removeNode($name);

     public abstract function getNode($name=null);

     protected function getNodeId($name=null)
     {
         return $name==null? $this->nodes: $this->nodes[$name];
     }

     protected function createNodeByName($rootNodeObj, $name, $attributes, $pId)
     {
         $tmpObject = $rootNodeObj->createNodeObject($pId, $name, $attributes);
         $key = isset($attributes[id])?
         $name.'_'.$attributes[id]: $name.'_'.$this->getNodesSize();
         $this->setNode($key, $tmpObject->getSeq());
         return $tmpObject;
     }

     protected function removeNodeByName($rootNodeObj, $name)
     {
         $rootNodeObj->removeNodeById($this->getNodeId($name));
         if(sizeof($this->nodes)==1)
         $this->nodes = array();
         else
         unset($this->nodes[$name]);
     }

     protected function getNodeByName($rootNodeObj, $name=null)
     {
         if($name==null)
         {
             $tmpList = array();
             $tmpIds = $this->getNodeId();
             foreach($tmpIds as $key=>$id)
             $tmpList[$key] = $rootNodeObj->getNodeById($id);
             return $tmpList;
         }
         else
         {
             $id = $this->getNodeId($name);
             if($id===null)
             {
                 $tmpIds = $this->getNodeId();

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

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