php - Parsing SOAP response -


calling web service controller:

$client = new \soapclient("http://.../webservice/name_of_page.asmx?wsdl"); $result = $client->estadohabitacionesfechas(); 

i this:

<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="newdataset">     <xs:element name="newdataset" msdata:isdataset="true" msdata:maindatatable="tablaestadohabitacion" msdata:usecurrentlocale="true">         <xs:complextype>             <xs:choice minoccurs="0" maxoccurs="unbounded">                 <xs:element name="tablaestadohabitacion">                     <xs:complextype><xs:sequence>                         <xs:element name="idhabitacion" type="xs:int" minoccurs="0"/>                         <xs:element name="fechaentrada" type="xs:string" minoccurs="0"/>                         <xs:element name="fechasalida" type="xs:string" minoccurs="0"/>                     </xs:sequence>                 </xs:complextype>             </xs:element>         </xs:choice>     </xs:complextype> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">     <documentelement xmlns="">         <tablaestadohabitacion diffgr:id="tablaestadohabitacion1" msdata:roworder="0" diffgr:haschanges="inserted">             <idhabitacion>1</idhabitacion>             <fechaentrada>23/05/2012</fechaentrada>             <fechasalida>31/12/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion2" msdata:roworder="1" diffgr:haschanges="inserted">             <idhabitacion>2</idhabitacion>             <fechaentrada>23/05/2012</fechaentrada>             <fechasalida>29/06/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion3" msdata:roworder="2" diffgr:haschanges="inserted">             <idhabitacion>2</idhabitacion>             <fechaentrada>29/06/2012</fechaentrada>             <fechasalida>01/07/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion4" msdata:roworder="3" diffgr:haschanges="inserted">             <idhabitacion>3</idhabitacion>             <fechaentrada>02/06/2012</fechaentrada>             <fechasalida>03/06/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion5" msdata:roworder="4" diffgr:haschanges="inserted">             <idhabitacion>3</idhabitacion>             <fechaentrada>29/06/2012</fechaentrada>             <fechasalida>01/07/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion6" msdata:roworder="5" diffgr:haschanges="inserted">             <idhabitacion>4</idhabitacion>             <fechaentrada>29/06/2012</fechaentrada>             <fechasalida>01/07/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion7" msdata:roworder="6" diffgr:haschanges="inserted">             <idhabitacion>5</idhabitacion>             <fechaentrada>02/06/2012</fechaentrada>             <fechasalida>03/06/2012</fechasalida>         </tablaestadohabitacion>         <tablaestadohabitacion diffgr:id="tablaestadohabitacion20" msdata:roworder="19" diffgr:haschanges="inserted">             <idhabitacion>10</idhabitacion>             <fechaentrada>02/06/2012</fechaentrada>             <fechasalida>03/06/2012</fechasalida>         </tablaestadohabitacion>     </documentelement> </diffgr:diffgram> 

how can parse data , use it?

you don't make clear "use" is, need form of xml parsing/search.

for example, try xml-loading string , var_dump result. enumerating various properties should show opportunities.

later on, might try xpath search , more advanced "tricks" speed work.

    // remove namespaces     $xml    = str_replace(array("diffgr:","msdata:"),'', $xml);     // wrap root element make standard xml     $xml    = "<package>".$xml."</package>";     // parse simplexml - there're better ways     $data   = simplexml_load_string($xml);     $rooms  = $data->package->diffgram->documentelement->tablaestadohabitacion;     print "we have " . count($rooms) . " rooms: \n";     foreach($rooms $i => $room)     {             print "room {$i}: id={$room['id']} (official id: {$room->idhabitacion}\n";             print "entrada {$room->fechaentrada}, salida {$room->fechasalida}\n...\n";     } 

there several parsers can use, quick , dirty one.

see more here.

large data sets

note: large xml data sets, i've found out foreach best.

and large data sets need few information, , whole file might not fit available memory, want use xmlparser, or xmlreader, , sift whole file through parser while keeping/manipulating (e.g. sending in db, or displaying html) information need.

while isn't in general practice, can turn output buffering off before entering long xml parsing loop, outputting html have , flush()ing once in while. outsource html http server, taking less memory in php process, @ expense of inferior compression (if output chunks of html of more 40k, difference negligible) , proportionally better responsivity (the user "sees" happen faster, if overall operation completion takes little longer. experience of faster load).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -