From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- utils/xml.php | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 utils/xml.php (limited to 'utils/xml.php') diff --git a/utils/xml.php b/utils/xml.php new file mode 100644 index 0000000..69059b0 --- /dev/null +++ b/utils/xml.php @@ -0,0 +1,126 @@ +parentnode = &$parentnode; + } + + public function addNode(&$node) + { + echo "

" . $this->name . "::addNode(" . $node->name . ")

"; + // $node->parent = &$this; + array_push($this->children, &$node); + } + + public function addAttribute($name, $value) + { + // echo "

" . $this->name . "::addAttribute(" . $name . ", ". $value . ")

"; + $attribute = new XMLDOMAttribute(); + $attribute->name = strtolower($name); + $attribute->value = $value; + array_push($this->attributes, &$attribute); + } + +} + +class XMLDOMReader +{ + private $parent; + private $curnode; + public $root; + + private function startThreadElement($parser, $name, $attribs) + { + $this->parent = &$this->curnode; + + $this->curnode = new XMLDOMNode(&$this->parent); + $this->curnode->name = $name; + + while (list($name, $value) = each($attribs)) { + $this->curnode->addAttribute($name, $value); + } + + $this->parent->addNode(&$this->curnode); + } + + private function dataThreadElement($parser, $data) + { + $this->curnode->contents = $data; + } + + private function endThreadElement($parser, $name) + { + $this->curnode = &$this->parent; + } + + public function XMLDOMReader($file) + { + $doc = new DOMDocument(); + $doc->load('book.xml'); + echo $doc->saveXML(); + + /* + $this->root = new XMLDOMNode(&$this->root); + $this->root->name = "root"; + $this->parent = &$this->root; + + // parse the xml file + $xml_parser = xml_parser_create("ISO-8859-1"); + xml_set_element_handler($xml_parser, "startThreadElement", "endThreadElement"); + xml_set_character_data_handler($xml_parser, "dataThreadElement"); + xml_set_object ( $xml_parser, $this ); + + $data = file_get_contents($file); + + if (!xml_parse($xml_parser, $data, true)) { + die(sprintf("XML error: %s at line %d", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); + } + xml_parser_free($xml_parser); + */ + + // $parent; + /* + $this->root = new XMLDOMNode(&$this->root); + $this->root->name = "Root"; + + $node0 = new XMLDOMNode(&$this->root); + $node0->name = "Node1"; + array_push($this->root->children, &$node0); + // $this->root->addNode(&$node0); + + $node1 = new XMLDOMNode(&$node0); + $node1->name = "Node1.1"; + array_push($node0->children, &$node1); + // $node0->addNode(&$node1); + + $node2 = new XMLDOMNode(&$node0); + $node2->name = "Node1.2"; + array_push($node0->children, &$node2); + // $node0->addNode(&$node2); + + echo "\n
";
+		echo $this->root . " - " . $node0 . " - " . $node1 . " - " . $node2 . "\n";
+		print_r($this->root);
+		echo "
\n"; + */ + } +} + + +?> \ No newline at end of file -- cgit v1.2.3