(PHP 5 >= 5.0.1)
SimpleXMLElement->children() — Trouve les enfants d'un node
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.
Par défaut, vaut FALSE
Version | Description |
---|---|
5.2.0 | Le paramètre optionnel is_prefix a été ajouté. |
Exemple 2426. Traverser un pseudo-tableau children()
<?php
$xml
= new
SimpleXMLElement
(
'<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