(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DOMNode::getNodePath — Get an XPath for a node
This function has no parameters.
Example #1 DOMNode::getNodePath() 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->getElementsByTagName('*') as $node) {
echo $node->getNodePath() . "\n";
}
?>
The above example will output:
/fruits /fruits/apples /fruits/apples/apple[1] /fruits/apples/apple[2] /fruits/pears /fruits/pears/pear
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant