PHP children() Function

Definition and Usage

The children() function retrieves the child nodes of the specified element.

Syntax

class SimpleXMLElement
{
string children(ns,is_prefix)
}
Parameter Description
ns Optional.
is_prefix Optional. The default is false.

Example

XML File:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

PHP Code:

<?php
$xml = simplexml_load_file("test.xml");
foreach ($xml->children() as $child)
  {
  echo "Child node: " . $child;
  }
?>

Output similar to:

Child node: George
Child node: John
Child node: Reminder
Child node: Don't forget the meeting!