(PHP 5 >= 5.2.0)
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.
Bir XPath yolu.
Başarısız olursa FALSE yoksa SimpleXMLElement nesnelerinden oluşan bir dizi 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');
while(list( , $node) = each($result)) {
echo '/a/b/c: ',$node,"\n";
}
/* Göreli yollar da çalışır... */
$result = $xml->xpath('b/c');
while(list( , $node) = each($result)) {
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.