CakeFest 2024: The Official CakePHP Conference

DOMNode::getNodePath

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

DOMNode::getNodePathノードの XPath を取得する

説明

public DOMNode::getNodePath(): ?string

ノードの XPath ロケーションパスを取得します。

パラメータ

この関数にはパラメータはありません。

戻り値

XPath を含む文字列、あるいはエラー時に null を返します。

例1 DOMNode::getNodePath() の例

<?php
// 新しい DOMDocument インスタンスを作ります
$dom = new DOMDocument;

// XML を読み込みます
$dom->loadXML('
<fruits>
<apples>
<apple>braeburn</apple>
<apple>granny smith</apple>
</apples>
<pears>
<pear>conference</pear>
</pears>
</fruits>
'
);

// 各要素の XPath を表示します
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

参考

add a note

User Contributed Notes

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