ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
_parse_proppatch.php
Go to the documentation of this file.
1 <?php
2 //
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
17 // | Christian Stocker <chregu@bitflux.ch> |
18 // +----------------------------------------------------------------------+
19 //
20 // $Id: _parse_proppatch.php,v 1.3 2004/01/05 12:41:34 hholzgra Exp $
21 //
22 
31 {
38  var $success;
39 
46  var $props;
47 
54  var $depth;
55 
62  var $mode;
63 
70  var $current;
71 
79  {
80  $this->success = true;
81 
82  $this->depth = 0;
83  $this->props = array();
84  $had_input = false;
85 
86  $f_in = fopen($path, "r");
87  if (!$f_in) {
88  $this->success = false;
89  return;
90  }
91 
92  $xml_parser = xml_parser_create_ns("UTF-8", " ");
93 
94  xml_set_element_handler($xml_parser,
95  array(&$this, "_startElement"),
96  array(&$this, "_endElement"));
97 
98  xml_set_character_data_handler($xml_parser,
99  array(&$this, "_data"));
100 
101  xml_parser_set_option($xml_parser,
102  XML_OPTION_CASE_FOLDING, false);
103 
104  while($this->success && !feof($f_in)) {
105  $line = fgets($f_in);
106  if (is_string($line)) {
107  $had_input = true;
108  $this->success &= xml_parse($xml_parser, $line, false);
109  }
110  }
111 
112  if($had_input) {
113  $this->success &= xml_parse($xml_parser, "", true);
114  }
115 
116  xml_parser_free($xml_parser);
117 
118  fclose($f_in);
119  }
120 
130  function _startElement($parser, $name, $attrs)
131  {
132  if (strstr($name, " ")) {
133  list($ns, $tag) = explode(" ", $name);
134  if ($ns == "")
135  $this->success = false;
136  } else {
137  $ns = "";
138  $tag = $name;
139  }
140 
141  if ($this->depth == 1) {
142  $this->mode = $tag;
143  }
144 
145  if ($this->depth == 3) {
146  $prop = array("name" => $tag);
147  $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
148  if ($this->mode == "set") {
149  $this->current["val"] = ""; // default set val
150  }
151  }
152 
153  if ($this->depth >= 4) {
154  $this->current["val"] .= "<$tag";
155  foreach ($attr as $key => $val) {
156  $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
157  }
158  $this->current["val"] .= ">";
159  }
160 
161 
162 
163  $this->depth++;
164  }
165 
174  function _endElement($parser, $name)
175  {
176  if (strstr($name, " ")) {
177  list($ns, $tag) = explode(" ", $name);
178  if ($ns == "")
179  $this->success = false;
180  } else {
181  $ns = "";
182  $tag = $name;
183  }
184 
185  $this->depth--;
186 
187  if ($this->depth >= 4) {
188  $this->current["val"] .= "</$tag>";
189  }
190 
191  if ($this->depth == 3) {
192  if (isset($this->current)) {
193  $this->props[] = $this->current;
194  unset($this->current);
195  }
196  }
197  }
198 
207  function _data($parser, $data) {
208  if (isset($this->current)) {
209  $this->current["val"] .= $data;
210  }
211  }
212 }
213 
214 ?>