Index: Node.php =================================================================== RCS file: /repository/pear/XML_Tree/Tree/Node.php,v retrieving revision 1.18 diff -u -r1.18 Node.php --- Node.php 11 Sep 2003 19:03:27 -0000 1.18 +++ Node.php 3 Apr 2004 23:54:41 -0000 @@ -51,6 +51,13 @@ var $content; /** + * Empty tag if no content specified (null) ex: (
in XHTML DTD ) + * + * @var boolean + */ + var $isEmptyTag = false; + + /** * Name of the node * * @var string @@ -64,9 +71,13 @@ * @param string content Node content (text) * @param array attributes Attribute-hash for the node */ - function XML_Tree_Node($name, $content = '', $attributes = array(), $lineno = null) + function XML_Tree_Node($name, $content = null, $attributes = array(), $lineno = null) { $this->name = $name; + if (is_null($content)) { + $content = ''; + $this->isEmptyTag = true; + } $this->setContent($content); $this->attributes = $attributes; $this->children = array(); @@ -85,7 +96,7 @@ * @return object reference to new child node * @access public */ - function &addChild($child, $content = '', $attributes = array(), $lineno = null) + function &addChild($child, $content = null, $attributes = array(), $lineno = null) { $index = sizeof($this->children); @@ -149,7 +160,7 @@ * @return Reference to the newly inserted node, or PEAR_Error upon insertion error. * @access public */ - function &insertChild($path,$pos,&$child, $content = '', $attributes = array()) + function &insertChild($path,$pos,&$child, $content = null, $attributes = array()) { $parent =& $this->getNodeAt($path); if (PEAR::isError($parent)) { @@ -235,20 +246,30 @@ $out .= ' ' . $name . '="' . $value . '"'; } - $out .= '>' . $this->content; - - if (sizeof($this->children) > 0) { - $out .= "\n"; - foreach ($this->children as $child) { - $out .= $child->get(); - } - } else { - $ident = ''; + if ($this->children || $this->content) { + $this->isEmptyTag = false; } - if ($do_ident) { - $out .= $ident . 'name . ">\n"; + if ($this->isEmptyTag) { + $out .= ' />'; + if ($do_ident) { + $out .= "\n"; + } } else { - $out .= 'name . '>'; + $out .= '>' . $this->content; + + if (sizeof($this->children) > 0) { + $out .= "\n"; + foreach ($this->children as $child) { + $out .= $child->get(); + } + } else { + $ident = ''; + } + if ($do_ident) { + $out .= $ident . 'name . ">\n"; + } else { + $out .= 'name . '>'; + } } $do_ident = true; } else {