17 require_once
'XML/Parser.php';
70 var $indent_xml =
false;
78 var $compact_array =
false;
101 if (!isset($xml)) $xml = &$this->array_xml;
103 $this->tag_level = 0;
108 $ret =
'<?xml version="1.0" encoding="utf-8"?>'.$ret;
128 $xml = file_get_contents($xml_file);
130 if ($xml !==
false) {
151 $this->parseString($xml);
153 return $this->array_xml[0];
171 $ret = $default_value;
173 if (isset($parent[$element_name][0][
'-content'])) {
174 $ret = $parent[$element_name][0][
'-content'];
193 $is_tag_open =
false;
195 $rc =
"\n".str_repeat(
"\t", $this->tag_level ? $this->tag_level - 1 : 0);
199 if (is_array($xml)) {
200 foreach ($xml as $xml_key => $xml_val) {
202 $is_tag_open |= !is_integer($xml_key);
204 if (is_array($xml_val)) {
206 if (count($xml_val)) {
208 $tag_name = $xml_key;
210 if (is_integer($xml_key)) {
211 $tag_name = $parent_tag;
219 if (!is_integer($xml_key)) $this->tag_level--;
226 if ($xml_key ==
'-content') {
228 $xml_val = str_replace(
'&',
'&', $xml_val);
231 else if ($xml_key{0} ==
'@') {
232 $xml_key = substr($xml_key, 1);
233 $attributes .=
" $xml_key=\"$xml_val\"";
237 $ret .=
"<$xml_key>$xml_val</$xml_key>";
243 if ($is_tag_open && $parent_tag) {
244 $ret =
"$rc<$parent_tag$attributes>$ret$optional_rc</$parent_tag>";
260 if (!empty($this->parser) && is_resource($this->parser)) {
261 xml_parser_free($this->parser);
277 $this->folding =
false;
278 $this->XML_Parser(null,
'event');
280 $this->array_xml = Array(Array());
295 foreach ($attribs as $attrib_name => $attrib_value) {
296 $new_tag[
'@'.$attrib_name] = $attrib_value;
299 $this->array_xml[] = &$new_tag;
312 $element_index = count($this->array_xml) - 1;
313 $element = &$this->array_xml[$element_index];
314 if (isset($element[
'-content'])) {
315 $element[
'-content'] = trim($element[
'-content']);
316 if ($element[
'-content'] ==
'') {
317 unset($this->array_xml[$element_index][
'-content']);
321 $this->array_xml[$element_index - 1][$elem][] = $element;
323 array_pop($this->array_xml);
338 $element = &$this->array_xml[count($this->array_xml) - 1];
339 if (!isset($element[
'-content'])) {
340 $element[
'-content'] =
'';
342 $element[
'-content'] .= $data;