Função PHP child()
Exemplo
Encontre os filhos do nó de nota:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
Definição e uso
A função children() encontra os filhos de um nó especificado.
Sintaxe
SimpleXMLElement::children(ns, prefix)
Valores de parâmetro
Parameter | Description |
---|---|
ns | Optional. Specifies an XML namespace |
prefix | Optional. A Boolean value. If TRUE ns is regarded as a prefix. If FALSE ns is regarded as a namespace URL. Default is FALSE |
Detalhes técnicos
Valor de retorno: | Retorna um objeto SimpleXMLElement |
---|---|
Versão do PHP: | 5.0+ |
Registro de alterações do PHP: | PHP 5.2: Adicionado o parâmetro prefixo opcional |
Mais exemplos
Exemplo
Encontre os filhos do nó do corpo:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body><span>Important!</span> Do
not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->body[0]->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
❮ Referência PHP SimpleXML