How to get XML data using PHP

  1. $xml_string="<?xml version='1.0'?>  
  2. <moleculedb>    
  3. <molecule name='ball'>    
  4. <symbol>ball</symbol>    
  5. <code>A</code>    
  6. </molecule>    
  7. <molecule name='car'>    
  8. <symbol>honda city</symbol>    
  9. <code>K</code>    
  10. </molecule>    
  11. </moleculedb>";    
  12.   
  13. $xml = simplexml_load_string($xml_string);  
  14.   
  15. foreach ($xml->molecule as $record)    
  16. {  
  17.   
  18. echo $record['name'], ' ';  
  19.   
  20. echo $record->symbol, ' ';  
  21.   
  22. echo $record->code, '<br />';  
  23.   
  24. }