array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'fr', ), 'this' => array ( 0 => 'domnode.getnodepath.php', 1 => 'DOMNode::getNodePath', ), 'up' => array ( 0 => 'class.domnode.php', 1 => 'DOMNode', ), 'prev' => array ( 0 => 'domnode.getlineno.php', 1 => 'DOMNode::getLineNo', ), 'next' => array ( 0 => 'domnode.getrootnode.php', 1 => 'DOMNode::getRootNode', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'fr', 'path' => 'reference/dom/domnode/getnodepath.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
DOMNode::getNodePath — Récupère un XPath pour un nœud
Cette fonction ne contient aucun paramètre.
Retourne un chaîne de caractères contenant le XPath, ou null
si une erreur survient.
Exemple #1 Exemple avec DOMNode::getNodePath()
<?php
// Crée une nouvelle instance DOMDocument
$dom = new DOMDocument;
// Charge le XML
$dom->loadXML('
<fruits>
<apples>
<apple>braeburn</apple>
<apple>granny smith</apple>
</apples>
<pears>
<pear>conference</pear>
</pears>
</fruits>
');
// Affiche le XPath pour chaque élément
foreach ($dom->getElementsByTagName('*') as $node) {
echo $node->getNodePath() . "\n";
}
?>
L'exemple ci-dessus va afficher :
/fruits /fruits/apples /fruits/apples/apple[1] /fruits/apples/apple[2] /fruits/pears /fruits/pears/pear