sub_title
 PHP
제   목 PHP - xml 읽어들이기(read) 클래스
작성자 오렌지 등록일 2009-02-08 02:48:23 조회수 9,398
PHP - xml 읽어들이기(read) 클래스

PHP 에서 xml 용 parser 클래스 입니다. 아직 테스트는 못해봤지만 잘 작동하리라 생각됩니다.

출처: https://svn.skumleren.net

<?php

class xmlread
  {

    var $tree = '$this->ogg';
    var $ogg    ;
    var $cnt = 0;

    /************
    * change_to_array
    * is called by startElement
    * to check if there is need
    * to change element to array
    ************/
    function change_to_array($test,$is_arr) {
    if ($test and !$is_arr):  //if element is set, change it to array
      eval('$tmp = '.$this->tree.';'); //save element to tmp
      eval('unset('.$this->tree.');'); //unset element
      eval(''.$this->tree.'= array();'); //transform $this->tree in an array
      eval('array_push('.$this->tree.',$tmp);');//push old object
                                                //into the array
      return true;
    endif;
    if ($is_arr)
      return true;
    }

    /************
    * startElement
    ************/
    function startElement($parser, $name, $attrs)
    {
      $this->tree = $this->tree."->".$name;  //add tag to tree string
                                            //test if element is an array
      eval('$is_arr = is_array('.$this->tree.');');
                                        //test if element is set
      eval('$test = isset('.$this->tree.');');
                                  //if is already set (and not array)...
                                  //...change it to array
      $is_arr = $this->change_to_array($test,$is_arr);

      if ($is_arr):                  //if is an array
        $this->cnt = $this->cnt+1;    //increase counter
                    //and set tree-string to add element
        $this->tree = $this->tree.'['.$this->cnt.']';
      endif;

    return true;}

    /************
    * characterData
    ************/
    function characterData($parser, $data)
    {
      if (trim($data)!=''):
        $data = addslashes($data);
                //add data to tree set up by startElement()
        eval($this->tree."='".trim($data)."';");
      endif;
    return true;}

    /************
    * endElement
    ************/
    function endElement($parser, $name)
    { //cut last ->element
      $pos  = strrpos($this->tree, ">");
      $leng = strlen($this->tree);
      $pos1 = ($leng-$pos)+1;
      $this->tree = substr($this->tree, 0, -$pos1);
    return true;}

    /************
    * get_data: this is the
    * parser
    ************/
        function get_data
        ($doc,$st_el='startElement',
        $end_el='endElement',
        $c_data='characterData') {
        $this->mioparser = xml_parser_create();
        xml_set_object($this->mioparser, &$this);
        xml_set_element_handler
        ($this->mioparser, $st_el,$end_el);
        xml_set_character_data_handler
        ($this->mioparser,$c_data);
        xml_parser_set_option
        ($this->mioparser, XML_OPTION_CASE_FOLDING, false);
        xml_parse($this->mioparser,$doc);
        if (xml_get_error_code($this->mioparser)):
          print "<b>XML error at line n. ".
          xml_get_current_line_number
          ($this->mioparser)." -</b> ";
          print xml_error_string
            (xml_get_error_code($this->mioparser));
        endif;
    return true; }

    function xmlread($doc) {
        $xml = file_get_contents($doc);
        $this->get_data($xml);
    return true; }

   }  //end of class
 
?>

 
0
    
 
0
        list
 
※ 짧은 댓글일수록 예의를 갖추어 작성해 주시기 바랍니다.
line
reply cancel
 
번호 제목 글쓴이 추천 조회 날짜
55  PHP - 파일다운로드 함수   member 오렌지 0 / 0 12940 2009-03-07
54  fsockopen 함수를 이용해서 웹사이트에 데이터 전송하기   member 높이뜬새 2 / 0 11592 2009-03-06
53  PHP - 웹사이트의 유효성 체크   member 오렌지 0 / 0 7963 2009-02-28
52  PHP 현재 페이지의 도메인명이나 url등의 정보 알아오기   member 높이뜬새 6 / 0 108282 2009-02-27
51  PHP 파일 한줄 읽기(fgets함수)   admin 웹마당넷 0 / 0 32675 2009-02-24
50  PHP 파일 내용 읽기(fread함수)   admin 웹마당넷 3 / 0 27188 2009-02-15
49  PHP 파일 시스템(File System) 다루기 #1   admin 웹마당넷 0 / 0 21354 2009-02-14
48  PHP 썸네일(Thumbnail) 이미지 만들기 함수 첨부파일   member 티란투라 0 / 0 10645 2009-02-08
47  PHP - xml 읽어들이기(read) 클래스   member 오렌지 0 / 0 9398 2009-02-08
46  PHP와 자바스크립트를 이용한 드롭다운 메뉴 첨부파일   member 오렌지 0 / 0 11843 2009-02-07
45  PHP로 MySQL 데이터베이스 만들기(생성하기)   admin 웹마당넷 1 / 0 10407 2009-01-24
44  PHP MySQL 명령어 실행 함수 mysql_query   admin 웹마당넷 1 / 0 47227 2009-01-21
43  PHP 에러 처리 함수 die   admin 웹마당넷 4 / 0 41735 2009-01-20
42  PHP no-cache 설정(뒤로가기 막기)   admin 웹마당넷 1 / 0 31223 2009-01-17
41  PHP 폼(form)값의 유효성 체크   admin 운영자 0 / 0 9769 2009-01-13
40  PHP - SELECT로 반환된 레코드 갯수와 컬럼의 갯수를 알려주는 함수   admin 웹마당넷 0 / 0 18909 2009-01-11
39  PHP 버전 확인하기   admin 웹마당넷 0 / 0 13006 2009-01-06
38  PHP 한글 문자열 자르기   admin 웹마당넷 0 / 0 11833 2008-12-27
37  PHP 오늘날짜를 기준으로 이전,이후 날짜구하기   admin 웹마당넷 0 / 1 15205 2008-12-25
36  PHP 이름이 같은 폼태그(Form Tag)의 값(value) 처리하기   admin 웹마당넷 0 / 0 33195 2008-12-06
35  PHP split 함수를 이용한 문자열 분리   admin 웹마당넷 1 / 0 52817 2008-12-06
34  PHP explode 함수를 이용한 문자열 분리   admin 웹마당넷 0 / 0 11563 2008-12-01
33  PHP 달력(Calendar) 입니다. 이미지  [1] member 티란투라 0 / 0 11329 2008-11-16
32  플래쉬 무비클립을 캡쳐하는 PHP 소스 입니다. 첨부파일   member 사라마음 0 / 0 7103 2008-11-14
31  PHP에서 세션(session) 사용하기   member 웹스톤 0 / 0 14093 2008-08-31
write
button [1] [3] [4] button