PHP children() Fonction
Exemple
Trouvez les enfants du nœud note :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body>N'oubliez pas de me rappeler ce week-end !</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Nœud enfant : " . $child . "<br>";
}
?> Définition et Utilisation
La fonction children() permet de trouver les enfants d'un nœud spécifié.
Syntaxe
SimpleXMLElement::children( ns, prefix ) Valeurs des Paramètres
| Paramètre | Description |
|---|---|
| ns | Optionnel. Spécifie un espace de noms XML |
| prefix | Optionnel. Une valeur booléenne. Si TRUE, ns est considéré comme un préfixe. Si FALSE, ns est considéré comme une URL d'espace de noms. Par défaut, c'est FALSE. |
Détails Techniques
| Valeur de Retour : | Renvoie un objet SimpleXMLElement |
|---|---|
| Version PHP : | 5.0+ |
| Journal des Modifications PHP : | PHP 5.2 : Ajout du paramètre optionnel prefix |
Plus d'Exemples
Exemple
Trouvez les enfants du nœud body :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body><span>Important !</span> N'oubliez pas de me rappeler ce week-end !</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Nœud enfant : " . $child . "<br>";
}
?>