Parsing XML

<?php

   //simple xml
   $xmlData ="<!--?xml version='1.0'?-->
   <catalog>
       <language>
           <name>Php</name>
           <type>Server Side</type>
       </language>
       <language>
           <name>JavaScript</name>
           <type>Client Side</type>
       </language>
   </catalog>";
 
   //load the xml string using simplexml function
   $xml = simplexml_load_string($xmlData);
 
   //loop through the each node of molecule
   foreach ($xml->language as $language)
   {
      //node are accessted by -> operator
      echo $language->name, '  ';
      echo $language->type, '<br>';
   }
?>

Do you find this helpful?

Related articles