SimpleXMLElement->children

(no version information, might be only in CVS)

SimpleXMLElement->children -- Trouve les enfants d'une node

Description

SimpleXMLElement simplexml_element->children ( void )

Cette méthode trouve le fils de l'élément dont il est membre. Le résultat suit les règles normales d'itération.

Note : SimpleXML ajoute des propriétés itératives pour presque toutes ses méthodes. Celles-ci ne peuvent être vues en utilisant var_dump() ou tout autre fonction qui examine les objets.

Exemple 1. Traverser un pseudo-tableau children()

<?php
$xml
= simplexml_load_string(
'<person>
<child role="son">
  <child role="daughter"/>
</child>
<child role="daughter">
  <child role="son">
   <child role="son"/>
  </child>
</child>
</person>'
);

foreach (
$xml->children() as $second_gen) {
    echo
' The person begot a ' . $second_gen['role'];

    foreach (
$second_gen->children() as $third_gen) {
        echo
' who begot a ' . $third_gen['role'] . ';';
    
        foreach (
$third_gen->children() as $fourth_gen) {
            echo
' and that ' . $third_gen['role'] .
                
' begot a ' . $fourth_gen['role'];
        }
    }
}
?>

L'exemple ci-dessus va afficher :

The person begot a son who begot a daughter; The person
begot a daughter who begot a son; and that son begot a son