With the help of Stackoverflow users I got quite a few steps of my problem. I have this XML witch is one of the child from the root node:
<ChannelStatistics ChannelId="DMAT" CounterDim="">
<TotalCount>104</TotalCount>
<DefectCounter ClassId="F1">62</DefectCounter>
<DefectCounter ClassId="F2">34</DefectCounter>
<DefectCounter ClassId="F3">8</DefectCounter>
</ChannelStatistics>
<ChannelStatistics ChannelI="FERRO" CounterDim="">
<TotalCount>17</TotalCount>
<DefectCounter ClassId="F1">2</DefectCounter>
<DefectCounter ClassId="F2">5</DefectCounter>
<DefectCounter ClassId="F3">10</DefectCounter>
</ChannelStatistics>
and using this php code
$obj = simplexml_load_file('data\data.xml');
foreach($obj->PieceReport->Piece->DeviceValuation->ChannelStatistics as $channel){
echo $channel->attributes()->ChannelId;
echo " - ";
foreach($channel->DefectCounter as $defect){
echo $defect->attributes()->ClassId, "= ";
echo $channel['ClassId']," " ;
}
echo "<br>" ;
}
I can get
DMAT - F1= F2= F3=
FERRO - F1= F2= F3=
but I'm stuck in how to get the values of F1, F3 and F3
What I need as result is:
DMAT - F1=62 F2=34 F3=8
FERRO - F1=2 F2=5 F3=10
So that I can save all of them in a Mysql database
Im new with XML and PHP so I guess this should be a easy one.
Any help appreciated!