PHP xpath()Function
Manuel de référence complet PHP SimpleXML
Définition et utilisation
La fonction xpath() exécute une requête XPath sur un document XML.
En cas de succès, la fonction renvoie un tableau d'objets SimpleXMLElements. En cas d'échec, elle renvoie FALSE.
Syntaxe
classe SimpleXMLElement
{
string xpath(path)
}
{
string xpath(path)
}
| Parameters | Description |
|---|---|
| path | Obligatoire. Spécifie le chemin XPath à rechercher dans le document XML. |
Exemple
Fichier XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body>Ne m'oubliez pas ce week-end !</body>
</note>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body>Ne m'oubliez pas ce week-end !</body>
</note>
Code PHP
<?php
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
Le code ci-dessus affichera :
Tableau
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Manuel de référence complet PHP SimpleXML Autres extensions