PHP children()Functions
PHP SimpleXML Reference Manual
Examples
Find the child nodes of the note node:
<?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>";
}
?>
Run Example »
Definition and Usage
The children() function finds the child nodes of the specified node.
Syntax
children(ns,is_prefix);
| Parameters | Description |
|---|---|
| ns | Optional. Specifies an XML namespace. |
| is_prefix | Optional. Specifies a boolean value. If the value is TRUE, thennsis a prefix. If the value is FALSE, thennsis a namespace URL. |
Technical Details
| Return value: | Returns a SimpleXMLElement object. |
|---|---|
| PHP Version: | 5.0.1+ |
| PHP Changelog: | Added theis_prefixparameter. |
More Examples
Example 1
Find the child nodes of the body node:
<?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>";
}
?>
Run Example »
PHP SimpleXML Reference Manual Other Extensions