Create a new SimpleXMLElement object, then output the content of the body node in PHP

Description

The following code shows how to create a new SimpleXMLElement object, then output the content of the body node.

Example


  /* w w w.  j a  v  a2 s.co m*/
<?php
   $note=<<<XML
   <note>
   <to>Work</to>
   <from>Home</from>
   <heading>Reminder</heading>
   <body>This is a message.</body>
   </note>
XML;
   
    $xml=new SimpleXMLElement($note);
    echo $xml->body;
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser