downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

simplexml_import_dom> <SimpleXMLElement::registerXPathNamespace
Last updated: Fri, 14 Aug 2009

view this page in

SimpleXMLElement::xpath

(PHP 5 >= 5.2.0)

SimpleXMLElement::xpathExécute une requête Xpath sur des données XML

Description

SimpleXMLElement
array xpath ( string $path )

La méthode xpath cherche dans le noeud SimpleXML des enfants qui correspondent au path Xpath.

Liste de paramètres

path

Un chemin XPath

Valeurs de retour

Retourne un tableau d'objets SimpleXMLElement ou FALSE si une erreur survient.

Exemples

Exemple #1 Xpath

<?php
$string 
= <<<XML
<a>
 <b>
  <c>text</c>
  <c>stuff</c>
 </b>
 <d>
  <c>code</c>
 </d>
</a>
XML;

$xml = new SimpleXMLElement($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.



add a note add a note User Contributed Notes
SimpleXMLElement::xpath
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites