24 function XMLStruct($a_name =
"", $a_attrs = array())
26 $this->name = $a_name;
27 $this->attrs = $a_attrs;
35 $struct =
new XMLStruct($a_name, $a_attrs);
36 $struct->parent =&
$GLOBALS[
"lastObj"];
39 $this->childs[] =& $struct;
56 $this->content[] = $a_data;
66 $newNode = $dom->create_element($this->name);
67 if ($this->content !=
"")
69 $newNode->set_content(implode(
"", $this->content));
71 if (is_array($this->attrs))
75 while (list (
$key, $val) = each ($this->attrs)) {
76 $newNode->set_attribute(
$key, $val);
79 $node = $node->append_child($newNode);
80 for ($j = 0; $j < count($this->childs); $j++)
82 $this->childs[$j]->insert($dom, $node);
84 $node = $node->parent_node();
93 $xml_parser = xml_parser_create(
"UTF-8");
94 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING,
false);
95 xml_set_object($xml_parser, $this);
96 xml_set_element_handler($xml_parser,
"startElement",
"endElement");
97 xml_set_character_data_handler($xml_parser,
"characterData");
99 if (!xml_parse($xml_parser, $a_xml,
true))
101 die(sprintf(
"XML error: %s at line %d",
102 xml_error_string(xml_get_error_code($xml_parser)),
103 xml_get_current_line_number($xml_parser)));
105 xml_parser_free($xml_parser);
112 foreach($attr as
$key => $value)
114 $attr[
$key] = preg_replace(
"/&(?!amp;|lt;|gt;|quot;)/",
"&",$attr[
$key]);
115 $attr[
$key] = preg_replace(
"/\"/",
""",$attr[$key]);
116 $attr[
$key] = preg_replace(
"/</",
"<",$attr[$key]);
117 $attr[
$key] = preg_replace(
"/>/",
">",$attr[$key]);
126 if (!is_object($this->xmlStruct))
129 $this->xmlStruct =
new XMLStruct($a_name, $a_attrs);
130 $GLOBALS[
"lastObj"] =& $this->xmlStruct;
134 $a_attrs = $this->
clean($a_attrs);
135 #var_dump("<pre>",++$counter," ",$a_name," -> ",$a_attrs,"<pre>");
136 $GLOBALS[
"lastObj"]->append($a_name, $a_attrs);
147 $a_data = preg_replace(
"/&/",
"&",$a_data);
149 $GLOBALS[
"lastObj"]->setContent($a_data);
154 $node = $this->xmlStruct->insert($dom, $node);