<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ include 'class.ArraytoXML'; $myFruits = simplexml_load_file("fruits.xml"); echo $myFruits->getName() . "<br>"; echo "<ul id='songlist'>\n"; foreach ($myFruits as $fruit) { $fruit_id = $fruit->fruit_id; $fruit_name = $fruit->fruit_name; $fruit_colour = $fruit->fruit_colour; $price_per_kg = $fruit->price_per_kg; echo "<li><div class='title'>" . $fruit_id . "</div><div class='artist'> " . $fruit_name . "</div><div>" . $fruit_colour . "</div></li>\n"; } echo "</ul>"; //map xml to array $myArraytoXML = new ArraytoXML(); $fruitArray = $myArraytoXML->toArray($myFruits); print "<pre>" . print_r($fruitArray, true) . "</pre>";
<?php include 'class.ArraytoXML'; $myFruits = array(array('fruit_id' => '1', 'fruit_name' => 'Banana', 'fruit_colour' => 'yellow', 'price_per_kg' => '2,99'), array('fruit_id' => '2', 'fruit_name' => 'Orange', 'fruit_colour' => 'orange', 'price_per_kg' => '245'), array('fruit_id' => '3', 'fruit_name' => 'Strawberry', 'fruit_colour' => 'red', 'price_per_kg' => '4,99')); //map array to XML $myArraytoXML = new ArraytoXML(); $fruitxml = $myArraytoXML->toXml($myFruits); print_r($fruitxml, true);