PHP Conference Nagoya 2025

DOMNode::getNodePath

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

DOMNode::getNodePathGet an XPath for a node

Beschreibung

public DOMNode::getNodePath(): ?string

Gets an XPath location path for the node.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

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

Beispiele

Beispiel #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";
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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

Siehe auch

add a note

User Contributed Notes

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