note 26686 added to function.xpath-eval
| From: | arthur at rack1 dot php dot net | Date: | Fri, 08 Nov 2002 21:54:42 +0000 |
| Subject: | note 26686 added to function.xpath-eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39202@lists.php.net to get a copy of this message | ||
If you want to get the XPath for a particular node:
function getXPath($node) {
/* node id is held in a property named '1', this is
illegal in php so we use a workaround */
$one = '1';
$xpath = '';
while ($parent = $node->parent_node()) {
$siblings = $parent->child_nodes();
$index = 1;
foreach ($siblings as $sibling) {
if ($sibling->type != XML_ELEMENT_NODE || $sibling->tagname != $node->tagname)
continue;
if ($sibling->$one == $node->$one) {
$xpath = '/' . $node->tagname . '[' . $index . ']'
. $xpath;
break;
}
$index++;
}
$node = $parent;
}
return $xpath;
}
--
http://www.php.net/manual/en/function.xpath-eval.php
http://master.php.net/manage/user-notes.php?action=edit+26686
http://master.php.net/manage/user-notes.php?action=delete+26686
http://master.php.net/manage/user-notes.php?action=reject+26686