Permalink
Browse files

* Checks that attributes passed to XML_Tree_Node::XML_Tree_Node() is …

…an array, if not, makes it one.

* CDATA only nodes now obey the <![CDATA[]]> section settings
* Output now has better formatting (especially CDATA only nodes

Modified:
XML_Tree_Node::XML_Tree_Node(); - See above
XML_Tree_Node::get(); - See above
XML_Tree_Node::setContent(); - Last arg now defaults to null as it should. Before it would turn off the global cdata section if you didn't specify a setting.


git-svn-id: http://svn.php.net/repository/pear/packages/XML_Tree/trunk@159717 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
dshafik committed May 26, 2004
1 parent 17ed0e8 commit ef9d41611dd3d7f3c5131db1020afc3ffe654921
Showing with 18 additions and 6 deletions.
  1. +18 −6 Tree/Node.php
View
@@ -103,6 +103,11 @@ function XML_Tree_Node($name, $content = '', $attributes = array(), $lineno = nu
$this->error =& $check_name;
return;
}
+
+ if (!is_array($attributes)) {
+ $attributes = array();
+ }
+
foreach ($attributes as $attribute_name => $value) {
$error = XML_Tree::isValidName($attribute_name, 'Attribute');
if (PEAR::isError($error)) {
@@ -292,8 +297,8 @@ function &get($use_cdata_section = false)
static $do_ident = true;
$deep++;
$empty = false;
+ $ident = str_repeat(' ', $deep);
if ($this->name !== null) {
- $ident = str_repeat(' ', $deep);
if ($do_ident) {
$out = $ident . '<' . $this->name;
} else {
@@ -321,11 +326,11 @@ function &get($use_cdata_section = false)
if ($this->use_cdata_section == true || ($use_cdata_section == true && $this->use_cdata_section !== false)) {
if (trim($this->content) != '') {
$out .= '<![CDATA[' .$this->content. ']]>';
+ }
} else {
+ if (trim($this->content) != '') {
$out .= $this->content;
}
- } else {
- $out .= $this->content;
}
}
@@ -345,8 +350,15 @@ function &get($use_cdata_section = false)
}
$do_ident = true;
} else {
- $out = $this->content;
- $do_ident = false;
+ if ($this->use_cdata_section == true || ($use_cdata_section == true && $this->use_cdata_section !== false)) {
+ if (trim($this->content) != '') {
+ $out = $ident . '<![CDATA[' .$this->content. ']]>' . "\n";
+ }
+ } else {
+ if (trim($this->content) != '') {
+ $out = $ident . $this->content . "\n";
+ }
+ }
}
$deep--;
return $out;
@@ -406,7 +418,7 @@ function unsetAttribute($name)
* @access public
*/
- function setContent($content, $use_cdata_section = false)
+ function setContent($content, $use_cdata_section = null)
{
$this->use_cdata_section = $use_cdata_section;

0 comments on commit ef9d416

Please sign in to comment.