note 28061 deleted from function.xpath-eval by victor

From: Date: Wed, 01 Jan 2003 13:35:59 +0000
Subject: note 28061 deleted from function.xpath-eval by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-41539@lists.php.net to get a copy of this message
chregu wrote: $ctx->xpath_eval("xpath",$node); this is another way to get xpath??? doesn't work for me; always returns empty: /* function getXPath I added namespace support to the getXPath function above. Before using the xpath, you must call xpath_register_ns() like this: $ctx=xpath_new_context($domDocument); $ctx->xpath_register_ns('xm', 'http://www.xmlmake.com/xm'); $nodes = $ctx->xpath_eval($xpath); */ 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()) { $prefix = $node->prefix(); if (! empty( $prefix ) ){ $prefixStr = $prefix .':'; } $siblings = $parent->child_nodes(); $index = 1; foreach ($siblings as $sibling) { // if ($sibling->type != XML_ELEMENT_NODE || $sibling->tagname != $node->tagname) continue; if ($sibling->type != XML_ELEMENT_NODE || $sibling->tagname != $node->tagname || $sibling->prefix() != $prefix )continue; if ($sibling->$one == $node->$one) { $xpath = '/' . $prefixStr . $node->tagname . '[' . $index . ']' . $xpath; break; } $index++; } $node = $parent; } return $xpath; }// getXPath

« previous php.notes (#41539) next »