SimpleXMLElement->xpath()
(no version information, might be only in CVS)
SimpleXMLElement->xpath() --
Führt ein XPath Query auf XML-Daten aus
Beschreibung
class
SimpleXMLElement {
array
xpath ( string path )
}
Die xpath Methode durchsucht den SimpleXML Knoten nach
Kind-Elementen, die der XPath
path-Anfrage entsprechen. Die Funktion gibt immer
ein Array von SimpleXMLElement-Objekten zurück.
Beispiel 1. Xpath
<?php $string = <<<XML <a> <b> <c>text</c> <c>zeugs</c> </b> <d> <c>code</c> </d> </a> XML;
$xml = new SimpleXMLElement($string);
/* Suche nach <a><b><c> */ $result = $xml->xpath('/a/b/c');
while(list( , $node) = each($result)) { echo '/a/b/c: ',$node,"\n"; }
/* Relative Pfade funktionieren ebenfalls ... */ $result = $xml->xpath('b/c');
while(list( , $node) = each($result)) { echo 'b/c: ',$node,"\n"; } ?>
|
Das Skript erzeugt die Ausgaben:
/a/b/c: text
/a/b/c: zeugs
b/c: text
b/c: zeugs |
Beachten Sie, dass beide Ergebnisse gleich sind.
|