Esempio
Trovare i figli del nodo nota:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't
forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
Esempio Run » Definizione e l'utilizzo
Il children() funzione trova i figli di un nodo specificato.
Sintassi
children( ns,is_prefix );
Parametro | Descrizione |
---|---|
ns | Opzionale. Specifica un namespace XML |
is_prefix | Opzionale. Specifica un valore booleano. Se fosse vero, NS è considerato come un prefisso. Se FALSE, NS è considerato come un URL namespace |
Dettagli tecnici
Valore di ritorno: | Restituisce un oggetto SimpleXMLElement |
---|---|
Versione PHP: | 5.0.1+ |
PHP Changelog: | Il parametro è stato aggiunto is_prefix |
Altri esempi
esempio 1
Trovare i figli del nodo del corpo:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Don't forget me
this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as
$child)
{
echo "Child node: " . $child . "<br>";
}
?>
Esempio Run » <PHP SimpleXML di riferimento