Fonction PHP children()
Exemple
Trouvez les enfants du nœud de note :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
Définition et utilisation
La fonction children() trouve les enfants d'un nœud spécifié.
Syntaxe
SimpleXMLElement::children(ns, prefix)
Valeurs des paramètres
Parameter | Description |
---|---|
ns | Optional. Specifies an XML namespace |
prefix | Optional. A Boolean value. If TRUE ns is regarded as a prefix. If FALSE ns is regarded as a namespace URL. Default is 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 de préfixe |
Plus d'exemples
Exemple
Trouvez les enfants du nœud body :
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Do
not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
❮ Référence PHP SimpleXML