SimpleXMLElement->children
<<<
SimpleXMLElement->xpath simplexml_import_dom
>>>

8.111 Fonctions SimpleXML
8 Référence des fonctions
 Manuel PHP

Introduction
Pré-requis
Installation
Exemples
Constantes pré-définies
SimpleXMLElement->asXML
SimpleXMLElement->attributes
SimpleXMLElement->children
->SimpleXMLElement->xpath
simplexml_import_dom
simplexml_load_file
simplexml_load_string

8.111.9 SimpleXMLElement->xpath()Exécute une requête Xpath sur des données XML

[ Exemples avec simplexml_element_xpath ]   CVS uniquement

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.

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";
}
?>

<< SimpleXMLElement->xpath >>
SimpleXMLElement->children Fonctions SimpleXML simplexml_import_dom