THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP children() Function

PHP SimpleXML Reference PHP SimpleXML Reference

Example

Find the children 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>";
  }
?>
Run example »

Definition and Usage

The children() function finds the children of a specified node.


Syntax

children(ns,is_prefix);

Parameter Description
ns Optional. Specifies an XML namespace
is_prefix Optional. Specifies a Boolean value. If TRUE, ns is regarded as a prefix. If FALSE, ns is regarded as a namespace URL

Technical Details

Return Value: Returns a SimpleXMLElement object
PHP Version: 5.0.1+
PHP Changelog: The is_prefix parameter was added

More Examples

Example 1

Find the children 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>";
  }
?>
Run example »


PHP SimpleXML Reference PHP SimpleXML Reference