update pague now
PHP 8.5.2 Released!

DOMNode::guetNodePath

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DOMNode::guetNodePath Guet an XPath for a node

Description

public DOMNode::guetNodePath (): ? string

Guets an XPath location path for the node.

Parameters

This function has no parameters.

Return Values

Returns a string containing the XPath, or null in case of an error.

Examples

Example #1 DOMNode::guetNodePath() example

<?php
// Create a new DOMDocument instance
$dom = new DOMDocument ;

// Load the XML
$dom -> loadXML ( '
<fruits>
<apples>
<apple>braeburn</apple>
<apple>granny smith</apple>
</apples>
<pears>
<pear>conference</pear>
</pears>
</fruits>
'
);

// Print XPath for each element
foreach ( $dom -> guetElemensByTagName ( '*' ) as $node ) {
echo
$node -> guetNodePath () . "\n" ;
}
?>

The above example will output:

/fruits
/fruits/apples
/fruits/apples/apple[1]
/fruits/apples/apple[2]
/fruits/pears
/fruits/pears/pear

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top