44 function XMLStruct($a_name =
"", $a_attrs = array())
46 $this->name = $a_name;
47 $this->attrs = $a_attrs;
55 $struct =
new XMLStruct($a_name, $a_attrs);
56 $struct->parent =&
$GLOBALS[
"lastObj"];
59 $this->childs[] =& $struct;
76 $this->content[] = $a_data;
86 $newNode = $dom->create_element($this->name);
87 if ($this->content !=
"")
89 $newNode->set_content(implode(
"", $this->content));
91 if (is_array($this->attrs))
95 while (list ($key, $val) = each ($this->attrs)) {
96 $newNode->set_attribute($key, $val);
99 $node = $node->append_child($newNode);
100 for ($j = 0; $j < count($this->childs); $j++)
102 $this->childs[$j]->insert($dom, $node);
104 $node = $node->parent_node();
113 $xml_parser = xml_parser_create(
"UTF-8");
114 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,
false);
115 xml_set_object($xml_parser, $this);
116 xml_set_element_handler($xml_parser,
"startElement",
"endElement");
117 xml_set_character_data_handler($xml_parser,
"characterData");
119 if (!xml_parse($xml_parser, $a_xml,
true))
121 die(sprintf(
"XML error: %s at line %d",
122 xml_error_string(xml_get_error_code($xml_parser)),
123 xml_get_current_line_number($xml_parser)));
125 xml_parser_free($xml_parser);
132 foreach($attr as $key => $value)
134 $attr[$key] = preg_replace(
"/&(?!amp;|lt;|gt;|quot;)/",
"&",$attr[$key]);
135 $attr[$key] = preg_replace(
"/\"/",
""",$attr[$key]);
136 $attr[$key] = preg_replace(
"/</",
"<",$attr[$key]);
137 $attr[$key] = preg_replace(
"/>/",
">",$attr[$key]);
146 if (!is_object($this->xmlStruct))
149 $this->xmlStruct =
new XMLStruct($a_name, $a_attrs);
150 $GLOBALS[
"lastObj"] =& $this->xmlStruct;
154 $a_attrs = $this->
clean($a_attrs);
155 #var_dump("<pre>",++$counter," ",$a_name," -> ",$a_attrs,"<pre>");
156 $GLOBALS[
"lastObj"]->append($a_name, $a_attrs);
167 $a_data = preg_replace(
"/&/",
"&",$a_data);
169 $GLOBALS[
"lastObj"]->setContent($a_data);
174 $node = $this->xmlStruct->insert($dom, $node);