PHP XML - Child nodes retriving data -
i have problem in php. can retrive value of fist tag.
this xml file
<?xml version="1.0" encoding="utf-8"?> <response> <reservation id="000020" internalid="7366776" > <ccdata ccexpiredate="null/null" /> <reservationdetail id="2_0" currency="" /> <dayprice detailid="" roomid="2" day="2015-08-01" /> <dayprice detailid="" roomid="2" day="2015-08-02" /> </reservation> <reservation id="000010" internalid="7366642" > <ccdata cccode="michan" ccnumber="3000000000000" ccexpiredate="12/2016" /> <reservationdetail id="2_0" currency="usd" checkin="2015-07-01" /> <supplement detailid="" roomid="2" description="breakfast" /> <supplement detailid="" roomid="2" description="wifi" /> <supplement detailid="" roomid="2" description="transfer" /> <dayprice detailid="" roomid="2" day="2015-06-01" /> <dayprice detailid="" roomid="2" day="2015-06-02" /> <guest detailid="" roomid="2" firstname="rolando" /> <guest detailid="" roomid="2" firstname="jessica " /> </reservation> <reservation id="0005" internalid="7243828" > <ccdata cccode="453" ccnumber="34983483649365936539" ccexpiredate="05/2016" /> <reservationdetail id="2_0" currency="usd" checkin="2015-05-28" /> <dayprice detailid="" roomid="2" day="2015-05-29" /> <dayprice detailid="" roomid="2" day="2015-05-29" /> </reservation> </response>
and code of php retrive data
//supplement $cont=0; echo "sup >>>>> ".count($xml->reservation[$x]->supplement)."<br>"; { foreach($xml->reservation[$x]->supplement->attributes() $a => $b) { $texto='[supplement '.sprintf('%02d', $cont).'] '.$a.'="'.utf8_decode($b).'"'; echo $texto."<br>"; } $cont++; } while ($cont > 99);
this code output
[supplement 00] detailid="" [supplement 00] roomid="2" [supplement 00] description="breakfast"
instead of
[supplement 00] detailid="" [supplement 00] roomid="2" [supplement 01] description="breakfast" [supplement 01] detailid="" [supplement 01] roomid="2" [supplement 01] description="wifi" [supplement 02] detailid="" [supplement 02] roomid="2" [supplement 02] description="transfer"
is same problem tags dayprice , guest.
can me ?
thank in advance!!
your foreach
loop going through attributes of single supplement
. need 1 loop though each supplement
, next 1 loop through each attribute:
do { foreach($xml->reservation[$x]->supplement $supplement) { foreach($supplement->attributes() $a => $b) { $texto='[supplement '.sprintf('%02d', $cont).'] '.$a.'="'.utf8_decode($b).'"'; echo $texto."<br>"; } } $cont++; } while ($cont > 99);
note: $x
1
in case.
Comments
Post a Comment