update : 2015.11.03
php.shukuma.com

검색:
 
 
Get an XPath for a node

DOMNode::getNodePath

(PHP 5 >= 5.2.0, PHP 7)

DOMNode::getNodePathGet an XPath for a node

설명

public string DOMNode::getNodePath ( void )

Gets an XPath location path for the node.

인수

이 함수는 인수가 없습니다.

반환값

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

예제

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

위 예제의 출력:

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

참고