DOM DOMNode::getNodePath

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

DOMNode::getNodePath — 노드에 대한 XPath 가져오기


설명

public DOMNode::getNodePath(): ?string

노드의 XPath 위치 경로를 가져옵니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값

XPath를 포함하는 문자열을 반환하거나 오류의 경우 null을 반환합니다.


Examples

예제 #1 DOMNode::getNodePath() 예제

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

위의 예는 다음을 출력합니다.

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

기타