zoukankan      html  css  js  c++  java
  • xml_class来自 phpcms

    <?php

    class xml{
     var $parser;
     var $document;
     var $stack;
     var $data;
     var $last_opened_tag;
     var $isnormal;
     var $attrs=array();
     var $failed=false;
     function __construct($isnormal){
      $this->XMLparse($isnormal);
     }
     function XMLparse($isnormal){
      $this->isnormal=$isnormal;
      $this->parser=xml_parser_create('ISO-8859-1');
      xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,false);
      xml_set_object($this->parser,$this);
      xml_set_element_handler($this->parser,'open','close');
      xml_set_character_data_handler($this->parser,'data');
     }
     function destruct(){
      xml_parser_free($this->parser);
     }
     function parse(&$data){
      $this->document=array();
      $this->stack=array();
      return xml_parse($this->parser,$data,true)&&!$this->failed?$this->document:'';
     }
     function open(&$parser,$tag,$attributes){
      $this->data='';
      $this->failed=false;
      if(!$this->isnormal){
       if(isset($attributes['id'])&&!is_string($this->document[$attributes['id']])){
        $this->document=&$this->document[$attributes['id']];
       }else{
        $this->failed=true;
       }
      }else{
       if(!isset($this->document[$tag])||!is_string($this->document[$tag])){
        $this->document=&$this->document[$tag];
       }else{
        $this->failed=true;
       }
      }
      $this->stack[]=&$this->document;
      $this->last_opened_tag=$tag;
      $this->attrs=$attributes;
     }
     function data(&$parser,$data){
      if($this->last_opened_tag!=null){
       $this->data.=$data;
      }
     }
     function close(&$parser,$tag){
      if($this->last_opened_tag==$tag){
       $this->document=$this->data;
       $this->last_opened_tag=null;
      }
      array_pop($this->stack);
      if($this->stack){
       $this->document=&$this->stack[count($this->stack)-1];
      }
     }
    }
    ?>

  • 相关阅读:
    第一次c++团队合作项目第三篇随笔
    第一次c++团队合作项目第二篇随笔
    第一次c++团队合作作业期间第一篇随笔
    电梯调度程序
    给我留下深刻印象的三位老师
    一个带有富文本功能的记事本
    我也忘了第几次团队作业
    关于复数输入输出的一点见解
    c++团队作业工作笔记
    又要开始新的征程了hhh(这次内容比较感兴趣)
  • 原文地址:https://www.cnblogs.com/legend-song/p/3608224.html
Copyright © 2011-2022 走看看