In response to "simlee at indiana dot edu",
- First of all thanks for sharing your funciton.
- It didn't work for me so i rewrite it from scratch using different method.
Here is the new version, hope it helps someone :
<?php
function getNodeXPath( $node ) {
$result='';
while ($parentNode = $node->parentNode) {
$nodeIndex=-1;
$nodeTagIndex=0;
do {
$nodeIndex++;
$testNode = $parentNode->childNodes->item( $nodeIndex );
if ($testNode->nodeName==$node->nodeName and $testNode->parentNode->isSameNode($node->parentNode) and $testNode->childNodes->length>0) {
$nodeTagIndex++;
}
} while (!$node->isSameNode($testNode));
$result="/{$node->nodeName}[{$nodeTagIndex}]".$result;
$node=$parentNode;
};
return $result;
}
?>
By Sina.Salek.ws