(PHP 5, PHP 7, PHP 8)
SimpleXMLElement::xpath — Bir XML veri üzerinde bir XPath sorgusu çalıştırır
ifade ile belirtilen XPath
yoluyla eşleşen SimpleXMLElement düğümlerini
döndürür.
ifadeBir XPath yolu.
Başarısız olursa false yoksa SimpleXMLElement
nesnelerinden oluşan bir dizi veya null döndürür.
Örnek 1 - Xpath örneği
<?php
$string = <<<XML
<a>
<b>
<c>text</c>
<c>stuff</c>
</b>
<d>
<c>code</c>
</d>
</a>
XML;
$xml = new SimpleXMLElement($string);
/* Search for <a><b><c> */
$result = $xml->xpath('/a/b/c');
foreach ($result as $node) {
echo '/a/b/c: ',$node,"\n";
}
/* Göreli yollar da çalışır... */
$result = $xml->xpath('b/c');
foreach ($result as $node) {
echo 'b/c: ',$node,"\n";
}
?>Yukarıdaki örneğin çıktısı:
/a/b/c: text /a/b/c: stuff b/c: text b/c: stuff
İki sonucun da aynı oluşuna dikkat edin.