61 var $_array_paths = Array();
68 var $_results = Array();
82 var $_path_ptrs = Array();
98 $this->setArrayPaths($arr_paths);
107 function setArrayPaths($arr_paths)
109 $this->_array_paths = $arr_paths;
119 function &getArrayFromFile($filename, $arr_paths=Array())
121 if (count($arr_paths)) $this->setArrayPaths($arr_paths);
125 $err = $this->setInputFile($filename);
126 if (PEAR::isError($err)) {
130 $err = $this->parse();
131 if (PEAR::isError($err)) {
135 return $this->_results;
139 function getArrayFromString($str, $arr_paths=Array())
141 if (count($arr_paths)) $this->setArrayPaths($arr_paths);
145 $err = $this->parseString($str);
146 if (PEAR::isError($err)) {
149 return $this->_results;
158 function _initParse()
162 $this->folding =
false;
163 $this->XML_Parser(null,
'event');
165 $this->_results =
'';
167 $this->_path = Array();
168 $this->_path_ptrs = Array();
169 $this->_path_types = Array();
186 if (!count($this->_path)) {
187 $this->_path[] = $elem;
188 $this->_path_ptrs[] = &$this->_results;
189 $this->_path_types[] =
's';
195 $parent = &$this->_path_ptrs[count($this->_path_ptrs) - 1];
207 if (!isset($parent[$elem]) || !is_array($parent[$elem])) {
208 $parent[$elem] = Array();
212 $this->_path_types[count($this->_path_types) - 1] =
'c';
214 $this->_path[] = $elem;
215 $this->_path_types[] =
's';
216 $this->_path_ptrs[] = &$parent[$elem];
220 $path_str = implode(
'/', $this->_path);
221 if (in_array($path_str, $this->_array_paths)) {
222 $i = count($parent[$elem]);
223 $parent[$elem][$i] = Array();
225 $this->_path_ptrs[] = &$parent[$elem][$i];
233 $i = count($this->_path_ptrs) - 1;
234 for (reset($attribs); null !== ($k = key($attribs)); next($attribs)) {
235 $this->_path_ptrs[$i][
'@'.$k] = $attribs[$k];
256 if (count($this->_path) > 1) {
260 if ($this->_path_types[count($this->_path_types) - 1] ==
's' && $this->_cdata !=
'') {
261 $this->_path_ptrs[count($this->_path_ptrs) - 1][
'value'] = $this->_cdata;
278 $path_str = implode(
'/', $this->_path);
279 if (in_array($path_str, $this->_array_paths)) {
280 array_pop($this->_path_ptrs);
282 array_pop($this->_path_ptrs);
283 array_pop($this->_path_types);
284 array_pop($this->_path);
300 function cdataHandler($xp, $data)
302 if (trim($data) !=
'') {
303 $this->_cdata .= $data;
318 if (!empty($this->parser) && is_resource($this->parser)) xml_parser_free($this->parser);