PHP children() Function
Example
Find the children of the note node:
 <?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>";
  }
?> 
Run Example »
Definition and Usage
The children() function finds the children of a specified node.
Syntax
  SimpleXMLElement::children(ns, prefix)
Parameter Values
| 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 | 
Technical Details
| Return Value: | Returns a SimpleXMLElement object | 
|---|---|
| PHP Version: | 5.0+ | 
| PHP Changelog: | PHP 5.2: Added the optional prefix parameter | 
More Examples
Example
Find the children of the body node:
 <?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>";
  }
?>
Run Example »
❮ PHP SimpleXML Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.