From 2fe04a4707412ff2f4f8df5f5524bb1b2dcbb3d7 Mon Sep 17 00:00:00 2001 From: neoraider Date: Tue, 11 Apr 2006 18:05:04 +0000 Subject: XML-Parser und Modulverwaltung implementiert. --- code/xmlparser.inc.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 code/xmlparser.inc.php (limited to 'code/xmlparser.inc.php') diff --git a/code/xmlparser.inc.php b/code/xmlparser.inc.php new file mode 100644 index 0000000..2d53a1f --- /dev/null +++ b/code/xmlparser.inc.php @@ -0,0 +1,76 @@ +parser = xml_parser_create(); + + xml_set_object($this->parser, $this); + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); + + xml_set_element_handler($this->parser, 'openTagHandler', 'closeTagHandler'); + xml_set_character_data_handler($this->parser, 'cdataHandler'); + } + + function ParseFile($filename) { + $this->tags = array(); + $this->depth = 0; + + $file = fopen($filename, 'r'); + + while ($xml = fread($file, 4096)) { + if(!xml_parse($this->parser, $xml, feof($file))) { + $this->tags = null; + break; + } + } + + fclose($file); + + return $this->tags[0]; + } + + function ParseXML($xml) { + $this->tags = array(); + $this->depth = 0; + + if(!xml_parse($this->parser, $xml, true)) + $this->tags = null; + + return $this->tags[0]; + } + + function FindTag($data, $tag, $start = 0) { + for($i = $start; $i < count($data['children']); $i++) { + if(!is_array($data['children'][$i])) continue; + if($data['children'][$i]['tag'] == $tag) return $data['children'][$i]; + } + } + + function openTagHandler($parser, $name, $attribs) { + $this->tags[$this->depth] = array('tag' => $name, + 'attribs' => $attribs, + 'children' => array()); + + $this->depth++; + } + + function closeTagHandler($parser, $name) { + $this->depth--; + + if($this->depth > 0) + array_push($this->tags[$this->depth-1]['children'], $this->tags[$this->depth]); + } + + function cdataHandler($parser, $data) { + $data = trim($data); + + if($data != '') + array_push($this->tags[$this->depth-1]['children'], $data); + } + } + + $GLOBALS['xmlparser'] = new XMLParser; +?> -- cgit v1.2.3