Reading xml using php - Php

Read xml using php

Snippet Code


  
Rate this page :
  [ 0 votes]

This snippet can be used for to read and xml string

<?php //this is a sample xml string $xml_string="<?xml version='1.0'?> <moleculedb> <molecule name='books'> <symbol>on</symbol> <code>the table</code> </molecule> <molecule name='get'> <symbol>it</symbol> <code>right</code> </molecule> </moleculedb>"; //load the xml string using simplexml function $xml = simplexml_load_string($xml_string); //loop through the each node of molecule foreach ($xml->molecule as $record) { //attribute are accessted by echo $record['name'], ' '; //node are accessted by -> operator echo $record->symbol, ' '; echo $record->code, ' '; } ?>

Tags


Ask Questions

Ask Question