X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook