<?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];
  }
 }
}
?>

最新文章

  1. node.js问题二
  2. Database Initialization Strategies in Code-First:
  3. Android开发环境的发展演变
  4. Android配置----小米手机通过wifi连接ADB调试Android应用
  5. Android 下载文件 显示进度条
  6. Kafka的配置文件详细描述
  7. 垂直的seekbar
  8. git diff old mode 100755 new mode 100644
  9. Python字典处理技巧
  10. boost asio io_service学习笔记
  11. 老鸟都应该注意的git 提交规范
  12. JS网站当前日期在IE9、Chrome和FireFox中年份显示为113年的解决方法 getFullYear();
  13. Javascript日期格式化指定格式的字符串实现
  14. centos 日志文件
  15. SQL server 一些小结
  16. 二进制中的个数(JAVA)
  17. robotium之does not have a signature matching问题
  18. Java的三种代理模式(Proxy,CGLib)
  19. [转]【ROLLUP】Oracle分组函数之ROLLUP魅力
  20. codeforces#514 Div2---1059ABCD

热门文章

  1. android stutio 添加依赖
  2. Mybatis学习——初始MyBatis
  3. mysql脚本文件
  4. TensorFlow中的Session、Graph、operation、tensor
  5. 关于redis的使用总结
  6. 使用hexo+GitHub搭建个人博客的心得(含教程)
  7. 剑指offer【11】- 矩形覆盖
  8. Python Numpy中数据的常用的保存与读取方法
  9. Rails render collection 的魔法
  10. mysql SQL优化琐记之索引