cvs: php4 /pear/Experimental/XML Xml2obj.php

From: Date: Fri, 04 May 2001 12:50:55 +0000
Subject: cvs: php4 /pear/Experimental/XML Xml2obj.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-112@lists.php.net to get a copy of this message
cox Fri May 4 05:50:55 2001 EDT Modified files: /php4/pear/Experimental/XML Xml2obj.php Log: More in-line docs and examples and some vars renamed Index: php4/pear/Experimental/XML/Xml2obj.php diff -u php4/pear/Experimental/XML/Xml2obj.php:1.1 php4/pear/Experimental/XML/Xml2obj.php:1.2 --- php4/pear/Experimental/XML/Xml2obj.php:1.1 Thu May 3 15:06:36 2001 +++ php4/pear/Experimental/XML/Xml2obj.php Fri May 4 05:50:54 2001 @@ -21,10 +21,19 @@ require 'XML/Parser.php'; /* -* This class takes and xml file and maps it to an objects tree. It doesn't need -* DOM support, and the resultant tree is more easy (en limited) to handle. +* This class takes an xml file and maps it to an objects tree. It doesn't need +* DOM support, and the resultant tree is more easy (and limited) to handle. * Example of use: * +*<Package> +* <Name>XML Render</Name> +* <Maintainer> +* <Name>John Smith</Name> +* <Initials Type1="foo" Type2="bar">js</Initials> +* <Email>js@mail.com</Email> +* </Maintainer> +*</Package> +* * require './Xml2obj.php'; * PEAR::setErrorHandling(PEAR_ERROR_DIE); * $parser = new Xml2obj('./Pear_Package_Definition.xml'); @@ -36,8 +45,17 @@ * // Direct acces to attribs (returns an array): * print_r($tree->MAINTAINER->INITIALS->atts); * -* @author Tomas V.V.Cox <cox@idecnet.com> +* Current limitations: +* - It can only handle one equal element in the same tag. For ex: +* <root> +* <foo>Bar1</foo> +* <foo>Bar2</foo> <- +* </root> +* +* @todo - Ability to parse file descriptors and strings, besides files +* - Add methods for branch objects * +* @author Tomas V.V.Cox <cox@idecnet.com> */ class Xml2obj extends XML_Parser @@ -51,8 +69,8 @@ $this->folding = true; $this->XML_Parser(null, 'event'); $this->xmlfile = $file; - $GLOBALS['_XML_Xml2obj_data'] = array(); - $this->store = &$GLOBALS['_XML_Xml2obj_data']; + $GLOBALS['_XML_Xml2obj_root'] = array(); + $this->root = &$GLOBALS['_XML_Xml2obj_root']; } /* @@ -70,7 +88,7 @@ if (PEAR::isError($err)) { return $err; } - return $this->store; + return $this->root; } function StartHandler($xp, $elem, &$attribs) @@ -80,7 +98,7 @@ $new->name = $elem; // root element if (!isset($this->childs)) { - $this->store = $new; + $this->root = $new; // this will store the array of childs. For example: // $this->childs = array('MAINTAINER', 'INITIALS'); $GLOBALS['_XML_Xml2obj_childs'] = array(); @@ -98,9 +116,9 @@ function EndHandler($xp, $elem) { - $eval_str = $this->evalize(); - eval("\$new = & $eval_str;"); if (trim($this->cdata)) { + $eval_str = $this->evalize(); + eval("\$new = & $eval_str;"); // this will assign the "value" property for the // current object, only if it have one $new->value = $this->cdata; @@ -121,7 +139,7 @@ foreach ($this->childs as $child) { $eval_str .= "->$child"; } - return '$this->store' . $eval_str; + return '$this->root' . $eval_str; } /* @@ -135,7 +153,7 @@ /* * All objects of the Xml2obj tree are of this type. They'll -* only have properties, no methods. +* only have properties, no methods yet. * * @author Tomas V.V.Cox <cox@idecnet.com> */

« previous php.pear.cvs (#112) next »