PHP children()Funciones
Manual de referencia de PHP SimpleXML
Ejemplos
Busca los nodos secundarios del nodo note:
<?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>";
}
?>
$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>";
}
?>
Ejecutar ejemplo »
Definición y uso
La función children() busca los nodos secundarios del nodo especificado.
Sintaxis
children(ns,is_prefix);
| Parámetros | Descripción |
|---|---|
| ns | Opcional. Especifica un espacio de nombres XML. |
| is_prefix | Opcional. Especifica un valor booleano. Si el valor es TRUE, entoncesnses el prefijo. Si el valor es FALSE, entoncesnses la URL del espacio de nombres. |
Detalles técnicos
| Valor de retorno: | Retorna un objeto SimpleXMLElement. |
|---|---|
| Versión de PHP: | 5.0.1+ |
| Registro de cambios de PHP: | Se añadió elis_prefixparámetro. |
Más ejemplos
Ejemplo 1
Busca los nodos secundarios del nodo body:
<?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>";
}
?>
$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>";
}
?>
Ejecutar ejemplo »
Manual de referencia de PHP SimpleXML Otras extensiones