cvs: pear /XML_Tree Tree.php
| From: | Tomas V.V.Cox | Date: | Fri, 17 May 2002 12:15:23 +0000 |
| Subject: | cvs: pear /XML_Tree Tree.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3890@lists.php.net to get a copy of this message | ||
cox Fri May 17 08:15:23 2002 EDT
Modified files:
/pear/XML_Tree Tree.php
Log:
The class can now handle mixed element contents. It emulates
DOM_Text nodes with a XML_Tree_Node with no 'name' and 'children'
only 'content'.
Index: pear/XML_Tree/Tree.php
diff -u pear/XML_Tree/Tree.php:1.18 pear/XML_Tree/Tree.php:1.19
--- pear/XML_Tree/Tree.php:1.18 Thu May 16 10:42:22 2002
+++ pear/XML_Tree/Tree.php Fri May 17 08:15:23 2002
@@ -18,7 +18,7 @@
// | Tomas V.V.Cox <cox@idecnet.com> (tree mapping from xml file)|
// +----------------------------------------------------------------------+
//
-// $Id: Tree.php,v 1.18 2002/05/16 14:42:22 cox Exp $
+// $Id: Tree.php,v 1.19 2002/05/17 12:15:23 cox Exp $
//
require_once 'XML/Parser.php';
@@ -193,7 +193,6 @@
return $err;
}
$this->cdata = null;
- $this->store_cdata = false;
$err = $this->parse();
if (PEAR::isError($err)) {
return $err;
@@ -206,7 +205,6 @@
$this->folding = false;
$this->XML_Parser(null, 'event');
$this->cdata = null;
- $this->store_cdata = false;
$err = $this->parseString($str);
if (PEAR::isError($err)) {
return $err;
@@ -223,19 +221,24 @@
*
* @access private
*/
- function StartHandler($xp, $elem, &$attribs)
+ function startHandler($xp, $elem, &$attribs)
{
// root elem
if (!isset($this->i)) {
$this->obj1 =& $this->add_root($elem, null, $attribs);
$this->i = 2;
} else {
+ // mixed contents
+ if (!empty($this->cdata)) {
+ $parent_id = 'obj' . ($this->i - 1);
+ $parent =& $this->$parent_id;
+ $parent->children[] = &new XML_Tree_Node(null, $this->cdata);
+ }
$obj_id = 'obj' . $this->i++;
- $this->$obj_id =& new XML_Tree_Node($elem, null, $attribs);
+ $this->$obj_id = &new XML_Tree_Node($elem, null, $attribs);
}
$this->cdata = null;
- $this->store_cdata = true;
- return NULL;
+ return null;
}
/**
@@ -246,22 +249,28 @@
*
* @access private
*/
- function EndHandler($xp, $elem)
+ function endHandler($xp, $elem)
{
$this->i--;
if ($this->i > 1) {
$obj_id = 'obj' . $this->i;
// recover the node created in StartHandler
$node =& $this->$obj_id;
- $node->set_content($this->cdata);
+ // mixed contents
+ if (count($node->children) > 0) {
+ if (trim($this->cdata)) {
+ $node->children[] = &new XML_Tree_Node(null, $this->cdata);
+ }
+ } else {
+ $node->set_content($this->cdata);
+ }
$parent_id = 'obj' . ($this->i - 1);
$parent =& $this->$parent_id;
// attach the node to its parent node children array
$parent->children[] = $node;
}
$this->cdata = null;
- $this->store_cdata = false;
- return NULL;
+ return null;
}
/*
@@ -274,8 +283,7 @@
*/
function cdataHandler($xp, $data)
{
- // only store data inside tags
- if ($this->store_cdata) {
+ if (trim($data)) {
$this->cdata .= $data;
}
}