SimpleXMLElement->xpath
(no version information, might be only in CVS)
SimpleXMLElement->xpath -- Exécute une requête Xpath sur des données XML
Description
array
SimpleXMLElement->xpath ( string path )
La méthode xpath cherche dans la node SimpleXML des
enfants qui correspondent au path
Xpath.
Elle retourne toujours un tableau d'objets array SimpleXMLElement.
Exemple 1. Xpath
<?php $string = <<<XML <a> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML;
$xml = simplexml_load_string($string);
/* On cherche <a><b><c> */ $result = $xml->xpath('/a/b/c');
while(list( , $node) = each($result)) { echo '/a/b/c: ',$node,"\n"; }
/* Les chemins relatifs fonctionnent aussi... */ $result = $xml->xpath('b/c');
while(list( , $node) = each($result)) { echo 'b/c: ',$node,"\n"; } ?>
|
L'exemple ci-dessus va afficher : /a/b/c: text
/a/b/c: stuff
b/c: text
b/c: stuff |
Notez que les deux résultats sont égaux.
|