note 74734 deleted from language.oop5.basic by felipe

From: Date: Mon, 24 Mar 2008 22:12:52 +0000
Subject: note 74734 deleted from language.oop5.basic by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137472@lists.php.net to get a copy of this message
Note Submitter: realbart at hotmail dot com ---- Classes do not seem to be passed to functions. correctly in PHP4 I'll let you know when I find out why <?php class XmlNode { var $name; var $attrs; var $parentNode; var $firstChild; var $nextSibling; } function startElement($parser, $name, $attrs) { global $XmlRootNode; global $XmlPreviousSibling; global $XmlParentNode; if (is_null($XmlRootNode)) { $XmlRootNode = new XmlNode; $currentNode = &$XmlRootNode; } else { if (is_null($XmlParentNode->firstChild)) { $XmlParentNode->firstChild = new XmlNode; $currentNode = &$XmlParentNode->firstChild; } else { $XmlPreviousSibling->nextSibling = new XmlNode; $currentNode = &$XmlPreviousSibling->nextSibling; } $currentNode->parentNode = &$XmlParentNode; } $currentNode->name = $name; $currentNode->attrs = $attrs; $XmlPreviousSibling = &$currentNode; $XmlParentNode = &$currentNode; echo $XmlParentNode->name; } function endElement($parser, $name) { global $XmlParentNode; $XmlParentNode = &$XmlParentNode->parentNode; } // nothing wrong with these lines $file = "vragen.xml"; $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) die("could not open XML input"); while ($data = fread($fp, 4096)) if (!xml_parse($xml_parser, $data, feof($fp))) 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); //the xml file should now be converted to xml nodes... echo $XmlRootNode->name; // returns the name of the root object echo $XmlRootNode->firstChild; // should return "Object" yet returns nothing. echo $XmlRootNode->firstChild->name; // shoud return the name of the first object but doesn't echo $XmlRootNode->firstChild->nextSibling->name; //also returns nothing ?>

« previous php.notes (#137472) next »