cvs: pear /XML_Tree Node.php Tree.php package.xml

From: Date: Thu, 16 Aug 2001 06:56:04 +0000
Subject: cvs: pear /XML_Tree Node.php Tree.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-545@lists.php.net to get a copy of this message
sebastian Thu Aug 16 02:56:04 2001 EDT Modified files: /pear/XML_Tree Node.php Tree.php package.xml Log: Add missing example. Bump release date. Index: pear/XML_Tree/Node.php diff -u pear/XML_Tree/Node.php:1.1 pear/XML_Tree/Node.php:1.2 --- pear/XML_Tree/Node.php:1.1 Wed Aug 15 17:47:45 2001 +++ pear/XML_Tree/Node.php Thu Aug 16 02:56:04 2001 @@ -18,7 +18,7 @@ // | Christian Kühn <ck@chkuehn.de> | // +----------------------------------------------------------------------+ // -// $Id: Node.php,v 1.1 2001/08/15 21:47:45 sebastian Exp $ +// $Id: Node.php,v 1.2 2001/08/16 06:56:04 sebastian Exp $ // /** @@ -26,7 +26,7 @@ * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @package XML_Tree -* @version 1.0 15-Aug-2001 +* @version 1.0 16-Aug-2001 */ class XML_Tree_Node { /** @@ -98,6 +98,33 @@ } /** + * Returns text representation of this node. + * + * @return string xml + */ + function &get() { + $out = '<' . $this->name; + + foreach ($this->attributes as $name => $value) { + $out .= ' ' . $name . '="' . $value . '"'; + } + + $out .= '>' . $this->content; + + if (sizeof($this->children) > 0) { + $out .= "\n"; + + foreach ($this->children as $child) { + $out .= $child->get(); + } + } + + $out .= '</' . $this->name . ">\n"; + + return $out; + } + + /** * Gets an attribute by its name. * * @param string name @@ -140,33 +167,6 @@ */ function unset_attribute($name) { unset($this->attributes[strtolower($name)]); - } - - /** - * Returns text representation of this node. - * - * @return string xml - */ - function &get() { - $out = '<' . $this->name; - - foreach ($this->attributes as $name => $value) { - $out .= ' ' . $name . '="' . $value . '"'; - } - - $out .= '>' . $this->content; - - if (sizeof($this->children) > 0) { - $out .= "\n"; - - foreach ($this->children as $child) { - $out .= $child->get(); - } - } - - $out .= '</' . $this->name . ">\n"; - - return $out; } /** Index: pear/XML_Tree/Tree.php diff -u pear/XML_Tree/Tree.php:1.1 pear/XML_Tree/Tree.php:1.2 --- pear/XML_Tree/Tree.php:1.1 Wed Aug 15 17:47:45 2001 +++ pear/XML_Tree/Tree.php Thu Aug 16 02:56:04 2001 @@ -18,7 +18,7 @@ // | Christian Kühn <ck@chkuehn.de> | // +----------------------------------------------------------------------+ // -// $Id: Tree.php,v 1.1 2001/08/15 21:47:45 sebastian Exp $ +// $Id: Tree.php,v 1.2 2001/08/16 06:56:04 sebastian Exp $ // require_once 'XML/Tree/Node.php'; @@ -26,9 +26,24 @@ /** * PEAR::XML_Tree * +* Purpose +* +* Allows for the building of XML data structures +* using a tree representation, without the need +* for an extension like DOMXML. +* +* Example +* +* $tree = new XML_Tree; +* $root =& $tree->add_root('root'); +* $foo =& $root->add_child('foo'); +* +* header('Content-Type: text/xml'); +* $tree->dump(); +* * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @package XML_Tree -* @version 1.0 15-Aug-2001 +* @version 1.0 16-Aug-2001 */ class XML_Tree { /** @@ -62,6 +77,17 @@ } /** + * Add root node. + * + * @param string name of root element + * @return object reference to root node + */ + function &add_root($name) { + $this->root = new XML_Tree_Node($name); + return $this->root; + } + + /** * Get a copy of this tree. * * @return object XML_Tree @@ -71,14 +97,10 @@ } /** - * Add root node. - * - * @param string name of root element - * @return object reference to root node + * Print text representation of XML tree. */ - function &add_root($name) { - $this->root = new XML_Tree_Node($name); - return $this->root; + function dump() { + echo $this->get(); } /** @@ -94,10 +116,13 @@ } /** - * Print text representation of XML tree. + * Get current namespace. + * + * @param string namespace + * @return string */ - function dump() { - echo $this->get(); + function &get_name($name) { + return $this->root->get_element($this->namespace[$name]); } /** @@ -108,16 +133,6 @@ */ function register_name($name, $path) { $this->namespace[$name] = $path; - } - - /** - * Get current namespace. - * - * @param string namespace - * @return string - */ - function &get_name($name) { - return $this->root->get_element($this->namespace[$name]); } } ?> Index: pear/XML_Tree/package.xml diff -u pear/XML_Tree/package.xml:1.2 pear/XML_Tree/package.xml:1.3 --- pear/XML_Tree/package.xml:1.2 Wed Aug 15 17:47:45 2001 +++ pear/XML_Tree/package.xml Thu Aug 16 02:56:04 2001 @@ -5,7 +5,7 @@ <Name>XML_Tree</Name> <Summary> Allows for the building of XML data structures using a tree - representation, without the need for and extension like DOMXML. + representation, without the need for an extension like DOMXML. </Summary> <Maintainer> <Initials>SB</Initials> @@ -14,7 +14,7 @@ </Maintainer> <Release> <Version>1.0</Version> - <Date>2001-08-15</Date> + <Date>2001-08-16</Date> <Notes> This is the initial independent PEAR release. </Notes>

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