dr.pepper Posted September 28, 2011 Share Posted September 28, 2011 I am looking for some help parsing the SOAP request below: try { $aSoapConnectionOptions = array( 'cache_wsdl' => WSDL_CACHE_BOTH, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding' => 'ISO-8859-1', 'trace' => 1 ); $client = new SoapClient(WSDL_URI, $aSoapConnectionOptions); $xml = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ReceiveData xmlns="GDWebService"> <value> <![CDATA[ <?xml version="1.0" encoding="utf-8"?> <XMLRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Description>EventsOnlyListLoad</Description> <Item xsi:type="XMLEventsOnlyRequest"> <RangeStartDate>01/01/2006</RangeStartDate> <RangeEndDate>01/12/2012</RangeEndDate> <ResType /> <ResView>Web Sales Events</ResView> </Item> </XMLRequest> ]]> </value> </ReceiveData> </soap:Body> </soap:Envelope>'; $response = $client->__doRequest($xml,REQUEST_URL,"GDWebService/ReceiveData",'1.1'); When I print out the response, I get the following: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ReceiveDataResponse xmlns="GDWebService"><ReceiveDataResult><?xml version="1.0"?> <ResourceList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ResList> <anyType xsi:type="XMLEventsOnly"> <AVAILABLE>0</AVAILABLE> <EVENTNAME>Test Event</EVENTNAME> <RESTYPE>Families</RESTYPE> <TotalBooked>0</TotalBooked> <StartTime>11:00</StartTime> <ID>0069</ID> <EventCode>0000003701</EventCode> <EventDate>30/05/2011</EventDate> <EventDescription> </EventDescription> <Capacity>0</Capacity> <ProductMapID> </ProductMapID> <LongDescription> </LongDescription> <ImageLink> </ImageLink> <MINPERBOOKING>0</MINPERBOOKING> <MAXPERBOOKING>0</MAXPERBOOKING> <ValidFrom> </ValidFrom> <ValidTo> </ValidTo> <AdditionalInfo> </AdditionalInfo> <ValidDays> </ValidDays> <MoreInfoLink> </MoreInfoLink> </anyType> </ResList> <EventsOnly>false</EventsOnly> </ResourceList></ReceiveDataResult></ReceiveDataResponse></soap:Body></soap:Envelope> I want to be able to get the response as an object so I can easily loop through the ResList. Currently, the only way I seem to be able to do this is by doing the following but I know it's not the best code: $response = str_replace("xmlns=\"GDWebService\"", "", $response); $response = str_replace("soap:Body","body",$response); $response = simplexml_load_string($response); $response = $response->body->ReceiveDataResponse->ReceiveDataResult; $response = simplexml_load_string($response); if($response->ResList) foreach($response->ResList->anyType as $Item){ //echo data here } Hope someone can help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/ Share on other sites More sharing options...
dr.pepper Posted September 28, 2011 Author Share Posted September 28, 2011 Anyone?? Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/#findComment-1273649 Share on other sites More sharing options...
xyph Posted September 28, 2011 Share Posted September 28, 2011 It returns <EVENTNAME>Test Event</EVENTNAME> not <EVENTNAME>Test Event</EVENTNAME> ? Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/#findComment-1273674 Share on other sites More sharing options...
dr.pepper Posted September 28, 2011 Author Share Posted September 28, 2011 Yes. Not sure why. I can use HTML_entity_decode to get it like that though so would that help? Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/#findComment-1273685 Share on other sites More sharing options...
xyph Posted September 28, 2011 Share Posted September 28, 2011 I understand that. Just to confirm, if you had a value like... <EVENTNAME>Test <error> Event</EVENTNAME> ... it would end up like <EVENTNAME>Test <error> Event</EVENTNAME> If so... <?php $str = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ReceiveDataResponse xmlns="GDWebService"><ReceiveDataResult><?xml version="1.0"?> <ResourceList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ResList> <anyType xsi:type="XMLEventsOnly"> <AVAILABLE>0</AVAILABLE> <EVENTNAME>Test <error> Event</EVENTNAME> <RESTYPE>Families</RESTYPE> <TotalBooked>0</TotalBooked> <StartTime>11:00</StartTime> <ID>0069</ID> <EventCode>0000003701</EventCode> <EventDate>30/05/2011</EventDate> <EventDescription> </EventDescription> <Capacity>0</Capacity> <ProductMapID> </ProductMapID> <LongDescription> </LongDescription> <ImageLink> </ImageLink> <MINPERBOOKING>0</MINPERBOOKING> <MAXPERBOOKING>0</MAXPERBOOKING> <ValidFrom> </ValidFrom> <ValidTo> </ValidTo> <AdditionalInfo> </AdditionalInfo> <ValidDays> </ValidDays> <MoreInfoLink> </MoreInfoLink> </anyType> </ResList> <EventsOnly>false</EventsOnly> </ResourceList></ReceiveDataResult></ReceiveDataResponse></soap:Body></soap:Envelope>'; $str = htmlspecialchars_decode( $str ); // Cut out what we don't need from the string, avoid processing redundant info that could fail $start = strpos( $str, '<ResourceList' ); $end = strpos( $str, '</ResourceList>' ); $str = substr( $str, $start, $end-$start+15 ); $xml = new SimpleXMLElement( $str, LIBXML_NOERROR | LIBXML_NOWARNING ); print_r( $xml ); // VICTORY ?> Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/#findComment-1273711 Share on other sites More sharing options...
dr.pepper Posted September 29, 2011 Author Share Posted September 29, 2011 I understand that. Just to confirm, if you had a value like... <EVENTNAME>Test <error> Event</EVENTNAME> ... it would end up like <EVENTNAME>Test <error> Event</EVENTNAME> If so... <?php $str = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ReceiveDataResponse xmlns="GDWebService"><ReceiveDataResult><?xml version="1.0"?> <ResourceList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ResList> <anyType xsi:type="XMLEventsOnly"> <AVAILABLE>0</AVAILABLE> <EVENTNAME>Test <error> Event</EVENTNAME> <RESTYPE>Families</RESTYPE> <TotalBooked>0</TotalBooked> <StartTime>11:00</StartTime> <ID>0069</ID> <EventCode>0000003701</EventCode> <EventDate>30/05/2011</EventDate> <EventDescription> </EventDescription> <Capacity>0</Capacity> <ProductMapID> </ProductMapID> <LongDescription> </LongDescription> <ImageLink> </ImageLink> <MINPERBOOKING>0</MINPERBOOKING> <MAXPERBOOKING>0</MAXPERBOOKING> <ValidFrom> </ValidFrom> <ValidTo> </ValidTo> <AdditionalInfo> </AdditionalInfo> <ValidDays> </ValidDays> <MoreInfoLink> </MoreInfoLink> </anyType> </ResList> <EventsOnly>false</EventsOnly> </ResourceList></ReceiveDataResult></ReceiveDataResponse></soap:Body></soap:Envelope>'; $str = htmlspecialchars_decode( $str ); // Cut out what we don't need from the string, avoid processing redundant info that could fail $start = strpos( $str, '<ResourceList' ); $end = strpos( $str, '</ResourceList>' ); $str = substr( $str, $start, $end-$start+15 ); $xml = new SimpleXMLElement( $str, LIBXML_NOERROR | LIBXML_NOWARNING ); print_r( $xml ); // VICTORY ?> Thanks a lot. That has worked. Quote Link to comment https://forums.phpfreaks.com/topic/248043-how-to-parse-this-soap-request/#findComment-1273879 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.