Find the children of the body node in PHP

Description

The following code shows how to find the children of the body node.

Example


/*  w w  w .  ja v  a  2s.  c  o  m*/
<?php
   $note=<<<XML
       <note>
       <to>Work</to>
       <from>Home</from>
        <heading>Reminder</heading>
       <body><span>Important!</span> This is a message.</body>
       </note>
XML;

    $xml=simplexml_load_string($note);
    foreach ($xml->body[0]->children() as $child){
       echo "Child node: " . $child . "<br>";
    }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser