Friday, 27 February 2015

php how to read xml data file which contain category and sub category



i am trying read xml file from php and convert data into array here is my xml file code



<template>
<category name="Good">
<image name="abc" />
<image name="xyz" />
</category>
<category name="Baad">
<image name="123" />
<image name="asd" />
</category>
</template>


here is my code



$source = 'test.xml';

// load as string
$xmlstr = file_get_contents($source);
$xmlcont = new SimpleXMLElement($xmlstr);
foreach($xmlcont as $url)
{

}


can you please tell me how i print all data from xml file


No comments:

Post a Comment