I have an xml file containing data like below but I am doing a test run to see whether I can extract all the data. However I have trouble in getting the imgpath values.
<datas>
<projects>
<project>
<projectlogopath>logo1.gif</projectlogopath>
<groupname>group1</groupname>
<imgtitle>Company1</imgtitle>
<images>
<imgpath>comp1_sc01.jpg</imgpath>
<imgpath>comp1_sc02.jpg</imgpath>
<imgpath>comp1_sc03.jpg</imgpath>
</images>
</project>
<project>
<projectlogopath>logo2.gif</projectlogopath>
<groupname>group2</groupname>
<imgtitle>Company2</imgtitle>
<images>
<imgpath>comp2_sc01.jpg</imgpath>
</images>
</project>
</projects>
</datas>
This is what I wrote in php read the xml file
foreach($xml->children() as $projects){
foreach($projects->children() as $project => $data){
echo $data->projectlogopath;
echo "<br />";
echo $data->groupname;
echo "<br />";
echo $data->imgtitle;
echo "<br />";
foreach($data->images->children() as $data2) {
echo $data2->imgpath;
echo "<br />";
}
echo "***<br />";
}
}
My result looks like this. What have I done wrong? Thanks a lot
logo1.gif
group1
Company1
***
logo2.gif
group2
Company2
***
I am not sure what is your expected result is but try this changes:
foreach($data->images->children() as $imgpath=>$data2) {
echo $data2;
echo "<br />";
}