note 79744 added to ref.xml

From: Date: Tue, 11 Dec 2007 00:19:40 +0000
Subject: note 79744 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-133343@lists.php.net to get a copy of this message
There's a couple of vital flaws in aquariusrick's example: 1. Multiple tags of the same name will overwrite one another. 2. Text nodes within an element are all strung together, with no information saved regarding their order with respect to non-text nodes. It provided a good starting point, however, for a DOM-builder that *does* allow those things. This should be a more familiar structure for people used to DOM-walking in the browser; children of each node are stored in "childNodes". Text nodes are simply a child node that is only a string, instead of an array. $xml_parser = new xml(); $xml_parser->parse($xml); $dom = $xml_parser->dom; print_r($dom); class xml { var $parser; var $pointer; var $dom; function xml() { $this->pointer =& $this->dom; $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($this->parser, "tag_open", "tag_close"); xml_set_character_data_handler($this->parser, "cdata"); } function parse($data) { xml_parse($this->parser, $data); } function makeChildNode() { if (!isset($this->pointer['childNodes'])){ $this->pointer['childNodes'] = array(); } return count($this->pointer['childNodes']); } function tag_open($parser, $tag, $attributes) { $idx = $this->makeChildNode(); $this->pointer['childNodes'][$idx] = Array( '_idx' => $idx, 'tagName' => $tag, 'parentNode' => &$this->pointer, 'attributes' => $attributes, ); $this->pointer =& $this->pointer['childNodes'][$idx]; } function cdata($parser, $cdata) { $idx = $this->makeChildNode(); $this->pointer['childNodes'][$idx] = $cdata; //text node -- has no other attributes than the content } function tag_close($parser, $tag) { $idx =& $this->pointer['_idx']; $this->pointer =& $this->pointer['_parent']; unset($this->pointer['childNodes'][$idx]['_idx']); } } ---- Server IP: 64.71.164.2 Probable Submitter: 216.145.49.5 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/79744 Del: integrated -- https://master.php.net/note/delete/79744/integrated Del: useless -- https://master.php.net/note/delete/79744/useless Del: bad code -- https://master.php.net/note/delete/79744/bad+code Del: spam -- https://master.php.net/note/delete/79744/spam Del: non-english -- https://master.php.net/note/delete/79744/non-english Del: in docs -- https://master.php.net/note/delete/79744/in+docs Del: other reasons-- https://master.php.net/note/delete/79744 Reject -- https://master.php.net/note/reject/79744 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133343) next »