国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP中的類-操作XML(3)

2024-05-04 23:02:32
字體:
供稿:網(wǎng)友

 

/* here are the xml functions needed by expat */


   /* when expat hits an opening tag, it fires up this function */

   function startelement($parser, $name, $attrs) {

       array_push($this->current_tag, $name); // add tag to the cur. tag array

       $curtag = implode("_",$this->current_tag); // piece together tag

       /* this tracks what array index we are on for this tag */

       if(isset($this->tagtracker["$curtag"])) {
           $this->tagtracker["$curtag"]++;
       } else {
           $this->tagtracker["$curtag"]=0;
       }


       /* if there are attributes for this tag, we set them here. */

       if(count($attrs)>0) {
           $j = $this->tagtracker["$curtag"];
           if(!$j) $j = 0;

           if(!is_object($globals[$this->identifier]["$curtag"][$j])) {
               $globals[$this->identifier]["$curtag"][$j] = new xml_container;
           }

           $globals[$this->identifier]["$curtag"][$j]->store("attributes",$attrs);
               }

   } // end function startelement



   /* when expat hits a closing tag, it fires up this function */

   function endelement($parser, $name) {

       $curtag = implode("_",$this->current_tag);     // piece together tag
                               // before we pop it off,
                               // so we can get the correct
                               // cdata

       if(!$this->tagdata["$curtag"]) {
           $popped = array_pop($this->current_tag); // or else we screw up where we are
           return;     // if we have no data for the tag
       } else {
           $td = $this->tagdata["$curtag"];
           unset($this->tagdata["$curtag"]);
       }

       $popped = array_pop($this->current_tag);
                               // we want the tag name for
                               // the tag above this, it  
                               // allows us to group the
                               // tags together in a more
                               // intuitive way.

       if(sizeof($this->current_tag) == 0) return;     // if we aren't in a tag

       $curtag = implode("_",$this->current_tag);     // piece together tag
                               // this time for the arrays

       $j = $this->tagtracker["$curtag"];
       if(!$j) $j = 0;

       if(!is_object($globals[$this->identifier]["$curtag"][$j])) {
           $globals[$this->identifier]["$curtag"][$j] = new xml_container;
       }

       $globals[$this->identifier]["$curtag"][$j]->store($name,$td); #$this->tagdata["$curtag"]);
       unset($td);
       return true;
   }



   /* when expat finds some internal tag character data,
      it fires up this function */

   function characterdata($parser, $cdata) {
       $curtag = implode("_",$this->current_tag); // piece together tag        
       $this->tagdata["$curtag"] .= $cdata;
   }


   /* this is the constructor: automatically called when the class is initialized */

   function xml($data,$identifier='xml') {  

       $this->identifier = $identifier;

       // create parser object
       $this->xml_parser = xml_parser_create();

       // set up some options and handlers
       xml_set_object($this->xml_parser,$this);
       xml_parser_set_option($this->xml_parser,xml_option_case_folding,0);
       xml_set_element_handler($this->xml_parser, "startelement", "endelement");
       xml_set_character_data_handler($this->xml_parser, "characterdata");

       if (!xml_parse($this->xml_parser, $data, true)) {
           sprintf("xml error: %s at line %d",
           xml_error_string(xml_get_error_code($this->xml_parser)),
           xml_get_current_line_number($this->xml_parser));
       }

       // we are done with the parser, so let's free it
       xml_parser_free($this->xml_parser);

 

   }  // end constructor: function xml()


} // thus, we end our class xml

?>

 

注冊會(huì)員,創(chuàng)建你的web開發(fā)資料庫,
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 华宁县| 怀宁县| 神池县| 华蓥市| 乐亭县| 临猗县| 佛坪县| 嘉黎县| 湾仔区| 恭城| 务川| 城固县| 尉氏县| 泰和县| 定南县| 乌鲁木齐县| 晋中市| 三江| 木兰县| 湟源县| 五莲县| 吴桥县| 封丘县| 南阳市| 威信县| 仁寿县| 花莲县| 珲春市| 白城市| 沁水县| 观塘区| 济源市| 运城市| 康马县| 济南市| 石渠县| 密云县| 三江| 古交市| 太湖县| 黄浦区|