Output the data from each element in the XML file in PHP

Description

The following code shows how to output the data from each element in the XML file.

Example


/*from   ww w  .j  av  a2 s  . c o m*/
<?php
   $xml=simplexml_load_file("test.xml");
   echo $xml->to . "<br>";
   echo $xml->from . "<br>";
   echo $xml->heading . "<br>";
   echo $xml->body;
?>

The following code is for test.xml.


/*w w  w .j a va 2s .  c o m*/
    <?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Work</to>
    <from>Home</from>
    <heading>Reminder</heading>
    <body>This is a message.</body>
    </note>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser