Find the child nodes 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>"; }?>The children() function finds the child nodes of the specified node.
children( ns,is_prefix );
parameter | describe |
---|---|
ns | Optional. Specifies an XML namespace. |
is_prefix | Optional. Specifies a boolean value. If the value is TRUE, ns is the prefix. If the value is FALSE, ns is the namespace URL. |
Return value: | Returns a SimpleXMLElement object. |
---|---|
PHP version: | 5.0.1+ |
PHP change log: | Added is_prefix parameter. |
Find the child nodes 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>"; }?>