cvs: pear /XML_XPath/XPath common.php

From: Date: Fri, 12 Jul 2002 23:39:24 +0000
Subject: cvs: pear /XML_XPath/XPath common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5085@lists.php.net to get a copy of this message
dallen Fri Jul 12 19:39:24 2002 EDT Modified files: /pear/XML_XPath/XPath common.php Log: @ added the ability for the relative xpath query to take the '..' syntax for parent as the first argument...so array('..', 'foo') would get the child 'foo' from the parent of the pointer Index: pear/XML_XPath/XPath/common.php diff -u pear/XML_XPath/XPath/common.php:1.17 pear/XML_XPath/XPath/common.php:1.18 --- pear/XML_XPath/XPath/common.php:1.17 Wed Jun 12 17:23:55 2002 +++ pear/XML_XPath/XPath/common.php Fri Jul 12 19:39:24 2002 @@ -17,7 +17,7 @@ // | Authors: Dan Allen <dan@mojavelinux.com> | // +----------------------------------------------------------------------+ -// $Id: common.php,v 1.17 2002/06/12 21:23:55 dallen Exp $ +// $Id: common.php,v 1.18 2002/07/12 23:39:24 dallen Exp $ // }}} // {{{ description @@ -1352,14 +1352,19 @@ // {{{ void evaluate() /** - * Evaluate the xpath expression on the loaded xml document. An XML_XPath_Result object is - * returned which can be used to manipulate the results + * Evaluate the xpath expression on the loaded xml document. + * + * The xpath query provided is evaluated and either an XML_XPath_result object is + * returned, or, if the pointer is being moved, it acts like a glorified step function + * and moves the pointer to the specified node (or first node if it is a set) and returns + * a boolean success * * @param string $in_xpathQuery xpath query * @param boolean $in_movePointer (optional) move internal pointer * * @access public - * @return object result object {or XML_XPath_Error exception} + * @return mixed result object or boolean success (for move pointer) + * @throws XML_XPath_error XML_XPATH_NOT_LOADED */ function &evaluate($in_xpathQuery, $in_movePointer = false) { @@ -1380,11 +1385,21 @@ if ($in_xpathQuery[0] == 'current()' || $in_xpathQuery[0] == '.') { $in_xpathQuery[0] = $this->getNodePath($this->pointer); } + elseif ($in_xpathQuery[0] == 'parent()' || $in_xpathQuery[0] == '..') { + if ($this->pointer->node_type() != XML_DOCUMENT_NODE) { + $in_xpathQuery[0] = $this->getNodePath($this->pointer->parent_node()); + } + else { + $in_xpathQuery[0] = $this->getNodePath($this->pointer); + } + } else { $in_xpathQuery[0] = $this->getNodePath($in_xpathQuery[0]); } - $xpathQuery = $in_xpathQuery[0] . $sep . $in_xpathQuery[1]; + // handle or statements and construct query + $parts = explode('|', $in_xpathQuery[1]); + $xpathQuery = $in_xpathQuery[0] . $sep . implode('|' . $in_xpathQuery[0] . $sep, $parts); } else { $xpathQuery = reset($in_xpathQuery); @@ -1555,6 +1570,14 @@ if ($in_xpathQuery[0] == 'current()' || $in_xpathQuery[0] == '.') { $in_xpathQuery[0] = $this->getNodePath($this->pointer); + } + elseif ($in_xpathQuery[0] == 'parent()' || $in_xpathQuery[0] == '..') { + if ($this->pointer->node_type() != XML_DOCUMENT_NODE) { + $in_xpathQuery[0] = $this->getNodePath($this->pointer->parent_node()); + } + else { + $in_xpathQuery[0] = $this->getNodePath($this->pointer); + } } else { $in_xpathQuery[0] = $this->getNodePath($in_xpathQuery[0]);

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