PHP children()Fonctions

PHP SimpleXML 参考手册Manuel de référence PHP SimpleXML

Exemples

Trouver les nœuds enfants du nœud note :

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body>Ne m'oublie pas ce week-end !</body>
</note>
XML;

$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Nœud enfant : " . $child . "<br>";
}
?>

Exécuter l'exemple »

Définition et utilisation

La fonction children() trouve les nœuds enfants du nœud spécifié.


Syntaxe

children(ns,is_prefix);

Parameters Description
ns Facultatif. Spécifie un espace de noms XML.
is_prefix Facultatif. Spécifie une valeur booléenne. Si la valeur est TRUE, alorsnsest un préfixe. Si la valeur est FALSE, alorsnsest une URL d'espace de noms.

Détails techniques

Valeur de retour : Renvoie un objet SimpleXMLElement.
Version de PHP : 5.0.1+
Journal des modifications PHP : Ajout du paramètreis_prefix.


Plus d’exemples

Exemple 1

Trouvez les nœuds enfants du nœud body :

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Rappel</heading>
<body><span>Important !</span> Ne m'oubliez pas ce week-end !</body>
</note>
XML;

$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Nœud enfant : " . $child . "<br>";
}
?>

Exécuter l'exemple »



PHP SimpleXML 参考手册Manuel de référence SimpleXML PHP Autres extensions