cvs: pear /XML_XPath XPath.php
| From: | Daniel Allen | Date: | Thu, 06 Jun 2002 10:49:11 +0000 |
| Subject: | cvs: pear /XML_XPath XPath.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4443@lists.php.net to get a copy of this message | ||
dallen Thu Jun 6 06:49:11 2002 EDT
Modified files:
/pear/XML_XPath XPath.php
Log:
@ added the ability to do relative xpath queries by prepending the current location path
to the query when the third parameter is true
Index: pear/XML_XPath/XPath.php
diff -u pear/XML_XPath/XPath.php:1.9 pear/XML_XPath/XPath.php:1.10
--- pear/XML_XPath/XPath.php:1.9 Wed Jun 5 03:48:45 2002
+++ pear/XML_XPath/XPath.php Thu Jun 6 06:49:11 2002
@@ -17,7 +17,7 @@
// | Authors: Dan Allen <dan@mojavelinux.com> |
// +----------------------------------------------------------------------+
-// $Id: XPath.php,v 1.9 2002/06/05 07:48:45 dallen Exp $
+// $Id: XPath.php,v 1.10 2002/06/06 10:49:11 dallen Exp $
// }}}
// {{{ description
@@ -191,20 +191,33 @@
* @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;
}