Skip to content
Browse files

@ added the ability to do relative xpath queries by prepending the cu…

…rrent location path

to the query when the third parameter is true


git-svn-id: http://svn.php.net/repository/pear/packages/XML_XPath/trunk@84812 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 9ca6473 commit c14bdb8c7d6302530ed4eefe596e5cc064b57a22 Daniel Allen committed Jun 6, 2002
Showing with 14 additions and 1 deletion.
  1. +14 −1 XPath.php
View
15 XPath.php
@@ -191,20 +191,33 @@ function getOne($in_xpathQuery, $in_movePointer = false)
* @access public
* @return object result object {or XML_XPath_Error exception}
*/
- function evaluate($in_xpathQuery, $in_movePointer = false)
+ function evaluate($in_xpathQuery, $in_movePointer = false, $in_relative = false)
{
// Make sure we have loaded an xml document and were able to create an xpath context
if (!is_a_php_class($this->ctx, 'xpathcontext')) {
return PEAR::raiseError(null, XML_XPATH_NOT_LOADED, null, E_USER_ERROR, null, 'XML_XPath_Error', true);
}
+
+ if ($in_relative) {
+ $sep = '/';
+ // those double slashes cause an anomally
+ if (substr($in_xpathQuery, 0, 2) == '//') {
+ $sep = '';
+ }
+
+ $in_xpathQuery = $this->getNodePath($this->pointer) . $sep . $in_xpathQuery;
+ }
+
if (!$result = @xpath_eval($this->ctx, $in_xpathQuery)) {
return PEAR::raiseError(null, XML_XPATH_INVALID_QUERY, null, E_USER_WARNING, "XML_XPath query: $in_xpathQuery", 'XML_XPath_Error', true);
}
+
$resultObj = new XML_XPath_result($result, $in_xpathQuery, $this->xml, $this->ctx);
if ($in_movePointer && $resultObj->resultType() == XPATH_NODESET && $resultObj->numResults()) {
$this->setPointer($resultObj->getPointer());
}
+
return $resultObj;
}

0 comments on commit c14bdb8

Please sign in to comment.
Something went wrong with that request. Please try again.