PHP 8.1.2 Released!


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

DOMNode::getNodePathGet an XPath for a node


public DOMNode::getNodePath(): ?string

Gets an XPath location path for the node.


This function has no parameters.

Return Values

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


Example #1 DOMNode::getNodePath() example

// Create a new DOMDocument instance
$dom = new DOMDocument;

// Load the XML
  <apple>granny smith</apple>

// Print XPath for each element
foreach ($dom->getElementsByTagName('*') as $node) {
$node->getNodePath() . "\n";

The above example will output:


See Also

add a note add a note

User Contributed Notes

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