My XML format is this `
<?xml version='1.0' encoding='UTF-8'?>
<XMLResponse>
<ResponseType>HotelListResponse</ResponseType>
<RequestInfo>
<AffiliateCode>JD3622</AffiliateCode>
<AffRequestId>6</AffRequestId>
<AffRequestTime>2014-11-04T10:57:31</AffRequestTime>
</RequestInfo>
<TotalNumber>148703</TotalNumber>
<Hotels>
<Hotel>
<HotelCode>AD06PQ</HotelCode>
<OldHotelId>0</OldHotelId>
<DestinationId>AF6Z</DestinationId>
<Destination>Andorra La Vella</Destination>
<Country>Andorra</Country>
<HotelName>Domus Selecta Hotel Niunit</HotelName>
<StarRating>4</StarRating>
<HotelAddress>Ctra General Del Serrat S/n ANDORRA</HotelAddress>
<HotelPostalCode>AD300</HotelPostalCode>
<HotelPhoneNumber>+376 735735</HotelPhoneNumber>
<HotelArea></HotelArea>
<Chain></Chain>
<Coordinates>
<Latitude>42.616516</Latitude>
<Longitude>1.538348</Longitude>
</Coordinates>
<HotelImages>
<ImageURL>http://ift.tt/13HAgys;
<ImageURL>http://ift.tt/1E5qcui;
<ImageURL>http://ift.tt/13HAeXx;
<ImageURL>http://ift.tt/1E5qcuk;
<ImageURL>http://ift.tt/1E5qcum;
<ImageURL>http://ift.tt/13HAgyu;
<ImageURL>http://ift.tt/13HAgyw;
<ImageURL>http://ift.tt/1E5qf9A;
<ImageURL>http://ift.tt/13HAeXF;
<ImageURL>http://ift.tt/1E5qfpQ;
</HotelImages>
</Hotel>
<Hotel>
<HotelCode>AD0AT3</HotelCode>
<OldHotelId>0</OldHotelId>
<DestinationId>AF6Z</DestinationId>
<Destination>Andorra La Vella</Destination>
<Country>Andorra</Country>
<HotelName>HUSA MOLA PARK</HotelName>
<StarRating>3</StarRating>
<HotelAddress>Josep Viladomat, 22 - AD700 Andorra</HotelAddress>
<HotelPostalCode></HotelPostalCode>
<HotelPhoneNumber>00376 882000</HotelPhoneNumber>
<HotelArea></HotelArea>
<Chain></Chain>
<Coordinates>
<Latitude>42.511145</Latitude>
<Longitude>1.539706</Longitude>
</Coordinates>
<HotelImages>
<ImageURL>http://ift.tt/1E5qfpU;
<ImageURL>http://ift.tt/13HAgyC;
<ImageURL>http://ift.tt/1E5qcKF;
<ImageURL>http://ift.tt/1E5qcKH;
</HotelImages>
</Hotel>
`
And currently i am using the following approach to do this in codiegniter
function _getXML_Hotellist($fname){
$filename = $fname.'.xml';
$xmlfile='xml/'.$filename;
$xmlRaw = file_get_contents($xmlfile);
$xmlData = $this->simplexml->xml_parse($xmlRaw);
/* database for XMLResponse */
$result0['ResponseType'] = $xmlData['ResponseType'];
$result0['AffiliateCode'] = $xmlData['RequestInfo']['AffiliateCode'];
$result0['AffRequestId'] = $xmlData['RequestInfo']['AffRequestId'];
$result0['AffRequestTime'] = $xmlData['RequestInfo']['AffRequestTime'];
$result0['TotalNumber'] = $xmlData['TotalNumber'];
/* database for Hotel List */
foreach($xmlData['Hotel'] as $row) {
$result1['HotelCode']=$this->check_empty($row['HotelCode']);
$result1['OldHotelId']= $this->check_empty($row['OldHotelId']);
if(is_array($result1['OldHotelId'])) {
$result1['OldHotelId']= $result1['OldHotelId'][0];;
}
else {
$result1['OldHotelId']= $result1['OldHotelId'];
}
$result1['DestinationId']= $this->check_empty($row['DestinationId']);
$result1['Destination']= $this->check_empty($row['Destination']);
$result1['Country']= $this->check_empty($row['Country']);
$result1['HotelName']= $this->check_empty($row['HotelName']);
$result1['StarRating']= $this->check_empty($row['StarRating']);
$result1['HotelAddress']= $this->check_empty($row['HotelAddress']);
$result1['HotelPostalCode']= $this->check_empty($row['HotelPostalCode']);
$result1['HotelPhoneNumber']= $this->check_empty($row['HotelPhoneNumber']);
$result1['HotelArea']=$this->check_empty($row['HotelArea']);
$result1['Chain']=$this->check_empty($row['Chain']);
/* database for Hotels Location */
$result2['Latitude']=$this->check_empty($row['Coordinates']['Latitude']);
$result2['Longitude']=$this->check_empty($row['Coordinates']['Longitude']);
$result2['HotelCode']= $this->check_empty($row['HotelCode']);
/* database for Hotels Images */
$result4['HotelCode']= $this->check_empty($row['HotelCode']);
$result3['ImageURL']=$row['HotelImages']['ImageURL'];
if(empty($result3['ImageURL'])) {
$result4['ImageURL']="";
$this->db->insert('cf_hotel_images',$result4);
}
else {
if(is_array($result3['ImageURL'])) {
foreach($result3['ImageURL'] as $row) {
$result4['ImageURL']=$row;
$this->db->insert('cf_hotel_images',$result4);
}
}
else {
$result4['ImageURL']= $result3['ImageURL'];
$this->db->insert('cf_hotel_images',$result4);
}
}
/* database Queries */
$this->db->insert('cf_hotel_list',$result1);
$this->db->insert('cf_coordinates',$result2);
}
//$this->db->insert('cf_xml_response',$result0);
}
This is working but, this is very slow and expires every time and also taking too many hours. so please suggest me some another solution.
No comments:
Post a Comment