cvs: pear /XML_Tree/Tree Node.php

From: Date: Thu, 16 May 2002 14:43:27 +0000
Subject: cvs: pear /XML_Tree/Tree Node.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3863@lists.php.net to get a copy of this message
cox Thu May 16 10:43:27 2002 EDT Modified files: /pear/XML_Tree/Tree Node.php Log: Beautify the output of $node->get() with identation Index: pear/XML_Tree/Tree/Node.php diff -u pear/XML_Tree/Tree/Node.php:1.6 pear/XML_Tree/Tree/Node.php:1.7 --- pear/XML_Tree/Tree/Node.php:1.6 Sat Mar 23 09:32:02 2002 +++ pear/XML_Tree/Tree/Node.php Thu May 16 10:43:27 2002 @@ -18,7 +18,7 @@ // | Christian Kühn <ck@chkuehn.de> (escape xml entities) | // +----------------------------------------------------------------------+ // -// $Id: Node.php,v 1.6 2002/03/23 14:32:02 mj Exp $ +// $Id: Node.php,v 1.7 2002/05/16 14:43:27 cox Exp $ // /** @@ -135,10 +135,10 @@ */ function &insertChild($path,$pos,&$child, $content = '', $attributes = array()) { // direct insert of objects useing array_splice() faild :( - array_splice($this->children,$pos,0,'dummy'); + array_splice($this->children,$pos,0,'dummy'); if (is_object($child)) { // child offered is not instanziated // insert a single node - if (strtolower(get_class($child)) == 'xml_tree_node') { + if (strtolower(get_class($child)) == 'xml_tree_node') { $this->children[$pos]=&$child; } // insert a tree i.e insert root-element @@ -182,8 +182,12 @@ * * @return string xml */ - function &get() { - $out = '<' . $this->name; + function &get() + { + static $deep = -1; + $deep++; + $ident = str_repeat(' ', $deep); + $out = $ident . '<' . $this->name; foreach ($this->attributes as $name => $value) { $out .= ' ' . $name . '="' . $value . '"'; @@ -197,10 +201,12 @@ foreach ($this->children as $child) { $out .= $child->get(); } + } else { + $ident = ''; } - $out .= '</' . $this->name . ">\n"; - + $out .= $ident . '</' . $this->name . ">\n"; + $deep--; return $out; } @@ -286,7 +292,7 @@ $this->content = $this->_xml_entities($content); } - function set_content(&$content) + function set_content(&$content) { return $this->setContent(&$content); }

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