Index: Node.class.php =================================================================== --- Node.class.php (revision 5311) +++ Node.class.php (working copy) @@ -191,49 +191,15 @@ } /** - * Retrieve XML representation + * Protected helper method for getSource() * - * Setting indent to 0 (INDENT_DEFAULT) yields this result: - *
-     *     
-     *     Website created
-     *     
-     *     The first version of the XP web site is online
-     *     2002-12-27T13:10:00
-     *   
-     * 
- * - * Setting indent to 1 (INDENT_WRAPPED) yields this result: - *
-     *   
-     *     
-     *       Website created
-     *     
-     *     
-     *     
-     *       The first version of the XP web site is online
-     *     
-     *     
-     *       2002-12-27T13:10:00
-     *       
-     *   
-     * 
- * - * Setting indent to 2 (INDENT_NONE) yields this result (wrapped for readability, - * returned XML is on one line): - *
-     *   Website createdThe 
-     *   first version of the XP web site is online
-     *   2002-12-27T13:10:00
-     * 
- * - * @access public - * @param int indent default INDENT_WRAPPED - * @param string inset default '' - * @return string XML + * @access protected + * @param int indent + * @param string inset */ - function getSource($indent= INDENT_WRAPPED, $inset= '') { - $xml= $inset.'<'.$this->name; + function _getSource($indent, $inset) { + echo $inset, '<', $this->name; + switch (gettype($this->content)) { case 'string': $content= htmlspecialchars($this->content); @@ -267,44 +233,102 @@ if (!empty($this->attribute)) { $sep= (sizeof($this->attribute) < 3) ? '' : "\n".$inset; foreach (array_keys($this->attribute) as $key) { - $xml.= $sep.' '.$key.'="'.htmlspecialchars($this->attribute[$key]).'"'; + echo $sep, ' ', $key, '="', htmlspecialchars($this->attribute[$key]), '"'; } - $xml.= $sep; + echo $sep; } // No content and no children => close tag if (0 == strlen($content)) { - if (empty($this->children)) return $xml."/>\n"; - $xml.= '>'; + if (empty($this->children)) { + echo "/>\n"; + return; + } + echo '>'; } else { - $xml.= '>'.($indent ? "\n ".$inset.$content : trim($content)); + echo '>', ($indent ? "\n ".$inset.$content : trim($content)); } if (!empty($this->children)) { - $xml.= ($indent ? '' : $inset)."\n"; + echo ($indent ? '' : $inset), "\n"; foreach (array_keys($this->children) as $key) { - $xml.= $this->children[$key]->getSource($indent, $inset.' '); + $this->children[$key]->_getSource($indent, $inset.' '); } - $xml= ($indent ? substr($xml, 0, -1) : $xml).$inset; + echo $inset; + } else { + echo ($indent ? "\n".$inset : ''); } - return $xml.($indent ? "\n".$inset : '').'name.">\n"; + echo 'name, ">\n"; + return; case INDENT_NONE: foreach (array_keys($this->attribute) as $key) { - $xml.= ' '.$key.'="'.htmlspecialchars($this->attribute[$key]).'"'; + echo ' ', $key, '="', htmlspecialchars($this->attribute[$key]), '"'; } - $xml.= '>'.trim($content); + echo '>', trim($content); if (!empty($this->children)) { foreach (array_keys($this->children) as $key) { - $xml.= $this->children[$key]->getSource($indent, $inset); + $this->children[$key]->_getSource($indent, $inset); } } - return $xml.'name.'>'; + echo 'name, '>'; + return; } } /** + * Retrieve XML representation + * + * Setting indent to 0 (INDENT_DEFAULT) yields this result: + *
+     *     
+     *     Website created
+     *     
+     *     The first version of the XP web site is online
+     *     2002-12-27T13:10:00
+     *   
+     * 
+ * + * Setting indent to 1 (INDENT_WRAPPED) yields this result: + *
+     *   
+     *     
+     *       Website created
+     *     
+     *     
+     *     
+     *       The first version of the XP web site is online
+     *     
+     *     
+     *       2002-12-27T13:10:00
+     *       
+     *   
+     * 
+ * + * Setting indent to 2 (INDENT_NONE) yields this result (wrapped for readability, + * returned XML is on one line): + *
+     *   Website createdThe 
+     *   first version of the XP web site is online
+     *   2002-12-27T13:10:00
+     * 
+ * + * @access public + * @param int indent default INDENT_WRAPPED + * @param string inset default '' + * @return string XML + */ + function getSource($indent= INDENT_WRAPPED, $inset= '') { + ob_start(); + $this->_getSource($indent, $inset); + $xml= ob_get_contents(); + ob_end_clean(); + + return $xml; + } + + /** * Add a child node * * @access public