| 1 |
lars |
1 |
<?
|
|
|
2 |
/* ###################################################################################*/
|
|
|
3 |
/* ## Super Duper XMLParser ##*/
|
|
|
4 |
/* ###################################################################################*/
|
|
|
5 |
|
|
|
6 |
class XMLParser {
|
|
|
7 |
var $path;
|
|
|
8 |
var $result;
|
|
|
9 |
|
|
|
10 |
function XMLParser($encoding, $data) {
|
|
|
11 |
$this->path = "\$this->result";
|
|
|
12 |
$this->index = 0;
|
|
|
13 |
|
|
|
14 |
$xml_parser = xml_parser_create($encoding);
|
|
|
15 |
xml_parser_set_option( $xml_parser, XML_OPTION_CASE_FOLDING, FALSE);
|
|
|
16 |
xml_parser_set_option( $xml_parser, XML_OPTION_SKIP_WHITE, TRUE);
|
|
|
17 |
|
|
|
18 |
xml_set_object($xml_parser, &$this);
|
|
|
19 |
xml_set_element_handler($xml_parser, 'startElement', 'endElement');
|
|
|
20 |
xml_set_character_data_handler($xml_parser, 'characterData');
|
|
|
21 |
|
|
|
22 |
xml_parse($xml_parser, $data, true);
|
|
|
23 |
xml_parser_free($xml_parser);
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
function startElement($parser, $tag, $attributeList) {
|
|
|
27 |
eval("\$vars = get_object_vars(".$this->path.");");
|
|
|
28 |
$this->path .= "->".$tag;
|
|
|
29 |
if ($vars and array_key_exists($tag, $vars)) {
|
|
|
30 |
eval("\$data = ".$this->path.";");
|
|
|
31 |
if (is_array($data)) {
|
|
|
32 |
$index = sizeof($data);
|
|
|
33 |
$this->path .= "[".$index."]";
|
|
|
34 |
} else if (is_object($data)) {
|
|
|
35 |
eval($this->path." = array(".$this->path.");");
|
|
|
36 |
$this->path .= "[1]";
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
eval($this->path." = null;");
|
|
|
40 |
|
|
|
41 |
foreach($attributeList as $name => $value)
|
|
|
42 |
eval($this->path."->".$name. " = '".XMLParser::cleanString($value)."';");
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
function endElement($parser, $tag) {
|
|
|
46 |
$this->path = substr($this->path, 0, strrpos($this->path, "->"));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
function characterData($parser, $data) {
|
|
|
50 |
eval($this->path." = '".trim($data)."';");
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
?>
|