The children() function finds the children of a specified node.
PHP children() Function has the following syntax.
children(ns,is_prefix);
Parameter | Is required | Description |
---|---|---|
ns | Optional. | An XML namespace |
is_prefix | Optional. | If TRUE, ns is regarded as a prefix. If FALSE, ns is regarded as a namespace URL |
Returns a SimpleXMLElement object
Find the children of the note node:
<?php//from w ww. j a v a2s . com
$note=<<<XML
<book>
<name>PHP</name>
<name>Java</name>
</book>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child){
echo "Child node: " . $child . "\n";
}
?>
The code above generates the following result.