CodeIgniter Forums
need help in converting xml to array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: need help in converting xml to array (/thread-64914.html)



need help in converting xml to array - goel.sandy86 - 04-10-2016

I am new to codeigniter and xml api also. i want to send below mention request to a srver in XML format. i want to use xmlrpc for the same. kindly help me in converting below mention xml to array so that xmlrpc will parse this array and output will be the same xml.


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <OTA_HotelAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05">
        <POS>
            <Source>
<RequestorID MessagePassword= "*****" ID= "****" Type="CHM"/>
</Source>
</POS>
<AvailRequestSegments>
<AvailRequestSegment>
<HotelSearchCriteria>
<Criterion>
<HotelRef HotelCode="00008164"/>
<StayDateRange Start="2016-04-01" End="2016-04-12">
</StayDateRange>
</Criterion>
</HotelSearchCriteria>
</AvailRequestSegment>
</AvailRequestSegments>
</OTA_HotelAvailRQ>


RE: need help in converting xml to array - cartalot - 04-10-2016

stack overflow is your new friend
http://stackoverflow.com/questions/23288151/codeigniter-process-simple-xml-php


RE: need help in converting xml to array - goel.sandy86 - 04-10-2016

tried this but not woking..


RE: need help in converting xml to array - John_Betong - 04-10-2016

http://php.net/manual/en/book.simplexml.php

Try this::
Three line xml2array:

<?php

$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

?>

Ta da!


RE: need help in converting xml to array - PaulD - 04-10-2016

That is brilliant! :-)