Permalink
Browse files

@ added the ability for the relative xpath query to take the '..' syn…

…tax for parent as

the first argument...so array('..', 'foo') would get the child 'foo' from the parent of the pointer


git-svn-id: http://svn.php.net/repository/pear/packages/XML_XPath/trunk@88529 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 88f9556 commit 302355b9218227d51f1c2ec7029a25c0c38b6207 Daniel Allen committed Jul 12, 2002
Showing with 27 additions and 4 deletions.
  1. +27 −4 XPath/common.php
View
@@ -1352,14 +1352,19 @@ function getOne($in_xpathQuery, $in_movePointer = false)
// {{{ 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 @@ function &evaluate($in_xpathQuery, $in_movePointer = false)
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);
@@ -1556,6 +1571,14 @@ function _quick_evaluate_init($in_xpathQuery = null, $in_movePointer = false, $i
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]);
}

0 comments on commit 302355b

Please sign in to comment.