Richard Winnick
asked on
help with simple xml php
A third party is send an xml file to me in a soap wrapper.
The var_dump of the result is as follows with the simplexml_load_string() warning and no result.
Warning: simplexml_load_string() expects parameter 1 to be string, object given.....
NULL
They have also tried another method which yields the following var_dump and warning -
Warning: simplexml_load_string() expects parameter 1 to be string, object given.....
NULL
I also tried using SimpleXMLElement() and I get the following fatal error for both methods -
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__const ruct() expects parameter 1 to be string, object given' in....construct(Object(std Class)) #1 {main}
What am I missing?
Thanks for any and all assistance in advance -
Richard
The var_dump of the result is as follows with the simplexml_load_string() warning and no result.
object(stdClass)#2 (1) { ["XMLGetStatusTrackerInfoResult"]=> string(3473) " 2515403106 OWN Rack 04/02/2016 04/06/2016 ALLERGY 04/06/2016 John Test 4332323 2512243697 GRP Rack 04/01/2016 04/04/2016 E-ARRIVAL 04/08/2016 Harvey Jones 3105551212 2515403106 TRAN Rack 04/06/2016 04/13/2016 E-TOWEL 2512243708 TRAN Rack 04/01/2016 04/08/2016 E-Blanket 04/09/2016 Harvey White 5145528789 " }
Warning: simplexml_load_string() expects parameter 1 to be string, object given.....
NULL
They have also tried another method which yields the following var_dump and warning -
object(stdClass)#2 (1) { ["GetStatusTrackerInfoResult"]=> object(stdClass)#3 (1) { ["StatusTracker"]=> array(4) { [0]=> object(stdClass)#4 (13) { ["Unit_id"]=> string(10) "2515403106" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(3) "OWN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/02/2016" ["Dpt_date"]=> string(10) "04/06/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(7) "ALLERGY" ["Next_arv_date"]=> string(10) "04/06/2016" ["Next_guest_name"]=> string(9) "John Test" ["Next_guest_cell_phone"]=> string(7) "4332323" } [1]=> object(stdClass)#5 (13) { ["Unit_id"]=> string(10) "2512243697" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(3) "GRP" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/01/2016" ["Dpt_date"]=> string(10) "04/04/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(9) "E-ARRIVAL" ["Next_arv_date"]=> string(10) "04/08/2016" ["Next_guest_name"]=> string(12) "Harvey Jones" ["Next_guest_cell_phone"]=> string(10) "3105551212" } [2]=> object(stdClass)#6 (13) { ["Unit_id"]=> string(10) "2515403106" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(4) "TRAN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/06/2016" ["Dpt_date"]=> string(10) "04/13/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(7) "E-TOWEL" ["Next_arv_date"]=> string(0) "" ["Next_guest_name"]=> string(0) "" ["Next_guest_cell_phone"]=> string(0) "" } [3]=> object(stdClass)#7 (13) { ["Unit_id"]=> string(10) "2512243708" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(4) "TRAN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/01/2016" ["Dpt_date"]=> string(10) "04/08/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(9) "E-Blanket" ["Next_arv_date"]=> string(10) "04/09/2016" ["Next_guest_name"]=> string(12) "Harvey White" ["Next_guest_cell_phone"]=> string(10) "5145528789" } } } }
Warning: simplexml_load_string() expects parameter 1 to be string, object given.....
NULL
I also tried using SimpleXMLElement() and I get the following fatal error for both methods -
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__const
What am I missing?
Thanks for any and all assistance in advance -
Richard
Share what you are exactly getting as SOAP response;
This appears to be the output of var_dump() when applied to a PHP object.
Once we can get a clear-text string from the API, we can work with it this way:
https://www.experts-exchange.com/articles/22519/Understanding-JSON-in-PHP-and-JavaScript-Applications.html
object(stdClass)#2 (1) { ["GetStatusTrackerInfoResult"]=> object(stdClass)#3 (1) { ["StatusTracker"]=> array(4) { [0]=> object(stdClass)#4 (13) { ["Unit_id"]=> string(10) "2515403106" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(3) "OWN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/02/2016" ["Dpt_date"]=> string(10) "04/06/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(7) "ALLERGY" ["Next_arv_date"]=> string(10) "04/06/2016" ["Next_guest_name"]=> string(9) "John Test" ["Next_guest_cell_phone"]=> string(7) "4332323" } [1]=> object(stdClass)#5 (13) { ["Unit_id"]=> string(10) "2512243697" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(3) "GRP" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/01/2016" ["Dpt_date"]=> string(10) "04/04/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(9) "E-ARRIVAL" ["Next_arv_date"]=> string(10) "04/08/2016" ["Next_guest_name"]=> string(12) "Harvey Jones" ["Next_guest_cell_phone"]=> string(10) "3105551212" } [2]=> object(stdClass)#6 (13) { ["Unit_id"]=> string(10) "2515403106" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(4) "TRAN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/06/2016" ["Dpt_date"]=> string(10) "04/13/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(7) "E-TOWEL" ["Next_arv_date"]=> string(0) "" ["Next_guest_name"]=> string(0) "" ["Next_guest_cell_phone"]=> string(0) "" } [3]=> object(stdClass)#7 (13) { ["Unit_id"]=> string(10) "2512243708" ["Arrival_departure"]=> string(0) "" ["Guest_type"]=> string(4) "TRAN" ["Rate_Type"]=> string(4) "Rack" ["Task_type"]=> string(0) "" ["Cleaning_levels"]=> string(0) "" ["Arv_date"]=> string(10) "04/01/2016" ["Dpt_date"]=> string(10) "04/08/2016" ["To_do_date"]=> string(0) "" ["Special_requests"]=> string(9) "E-Blanket" ["Next_arv_date"]=> string(10) "04/09/2016" ["Next_guest_name"]=> string(12) "Harvey White" ["Next_guest_cell_phone"]=> string(10) "5145528789" } } } }
My guess is that if they have a PHP StdClass object, they can use json_encode() to create a string representation of the object. Once they have the JSON string, they can send you that in almost any kind of API wrapper. A typical wrapper might be just a simple JSON string.Once we can get a clear-text string from the API, we can work with it this way:
https://www.experts-exchange.com/articles/22519/Understanding-JSON-in-PHP-and-JavaScript-Applications.html
@Ray_Paseur as we are getting object(stdClass)#2 (1) { as var_dump() result then it is json_decoded so we can use it directly as php object;
@rwinnick share code how you are trying to use this object;
@rwinnick share code how you are trying to use this object;
ASKER
Using htmlspecialchars($client-> __getLastR esponse()) -
This is the response to a method they are calling "GetInfo" -
Response:
<?xml version="1.0" encoding="utf-8"?><soap:En velope 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><G etStatusTr ackerInfoR esponse xmlns="http://iqwareinc.com/WebRes"><GetStatusTracker InfoResult ><StatusTr acker><Uni t_id>25154 03106</Uni t_id><Arri val_depart ure /><Guest_type>OWN</Guest_t ype><Rate_ Type>Rack< /Rate_Type ><Task_typ e /><Cleaning_levels /><Arv_date>04/02/2016</Ar v_date><Dp t_date>04/ 06/2016</D pt_date><T o_do_date /><Special_requests>ALLERG Y</Special _requests> <Next_arv_ date>04/06 /2016</Nex t_arv_date ><Next_gue st_name>Jo hn Test</Next_guest_name><Nex t_guest_ce ll_phone>4 332323</Ne xt_guest_c ell_phone> </StatusTr acker><Sta tusTracker ><Unit_id> 2512243697 </Unit_id> <Arrival_d eparture /><Guest_type>GRP</Guest_t ype><Rate_ Type>Rack< /Rate_Type ><Task_typ e /><Cleaning_levels /><Arv_date>04/01/2016</Ar v_date><Dp t_date>04/ 04/2016</D pt_date><T o_do_date /><Special_requests>E-ARRI VAL</Speci al_request s><Next_ar v_date>04/ 08/2016</N ext_arv_da te><Next_g uest_name> Harvey Jones</Next_guest_name><Ne xt_guest_c ell_phone> 3105551212 </Next_gue st_cell_ph one></Stat usTracker> <StatusTra cker><Unit _id>251540 3106</Unit _id><Arriv al_departu re /><Guest_type>TRAN</Guest_ type><Rate _Type>Rack </Rate_Typ e><Task_ty pe /><Cleaning_levels /><Arv_date>04/06/2016</Ar v_date><Dp t_date>04/ 13/2016</D pt_date><T o_do_date /><Special_requests>E-TOWE L</Special _requests> <Next_arv_ date /><Next_guest_name /><Next_guest_cell_phone /></StatusTracker><StatusT racker><Un it_id>2512 243708</Un it_id><Arr ival_depar ture /><Guest_type>TRAN</Guest_ type><Rate _Type>Rack </Rate_Typ e><Task_ty pe /><Cleaning_levels /><Arv_date>04/01/2016</Ar v_date><Dp t_date>04/ 08/2016</D pt_date><T o_do_date /><Special_requests>E-Blan ket</Speci al_request s><Next_ar v_date>04/ 09/2016</N ext_arv_da te><Next_g uest_name> Harvey White</Next_guest_name><Ne xt_guest_c ell_phone> 5145528789 </Next_gue st_cell_ph one></Stat usTracker> </GetStatu sTrackerIn foResult>< /GetStatus TrackerInf oResponse> </soap:Bod y></soap:E nvelope>
This is the response to a method they are calling "XMLGetInfo"
Response:
<?xml version="1.0" encoding="utf-8"?><soap:En velope 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><X MLGetStatu sTrackerIn foResponse xmlns="http://iqwareinc.com/WebRes"><XMLGetStatusTrac kerInfoRes ult><?x ml version='1.0' encoding='utf-16'?> <xs:schema id='DsStatusTracker' xmlns='' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas- microsoft- com:xml-ms data'> <xs:element name='DsStatusTracker' msdata:IsDataSet='true' msdata:UseCurrentLocale='t rue'> <xs:complexType> <xs:choice minOccurs='0' maxOccurs='unbounded'> <xs:element name='Reservation_status'& gt; <xs:complexType> <xs:sequence> <xs:element name='Unit_id' type='xs:string' minOccurs='0' /> <xs:element name='Arrival_departure' type='xs:string' minOccurs='0' /> <xs:element name='Guest_type' type='xs:string' minOccurs='0' /> <xs:element name='Rate_Type' type='xs:string' minOccurs='0' /> <xs:element name='Task_type' type='xs:string' minOccurs='0' /> <xs:element name='Cleaning_levels' type='xs:string' minOccurs='0' /> <xs:element name='Arv_date' type='xs:string' minOccurs='0' /> <xs:element name='Dpt_date' type='xs:string' minOccurs='0' /> <xs:element name='To_do_date' type='xs:string' minOccurs='0' /> <xs:element name='Special_requests' type='xs:string' minOccurs='0' /> <xs:element name='Next_arv_date' type='xs:string' minOccurs='0' /> <xs:element name='Next_guest_name' type='xs:string' minOccurs='0' /> <xs:element name='Next_guest_cell_phon e' 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-ms data' xmlns:diffgr='urn:schemas- microsoft- com:xml-di ffgram-v1' > <DsStatusTracker> <Reservation_status diffgr:id='Reservation_sta tus1' msdata:rowOrder='0'> <Unit_id>2515403106& lt;/Unit_i d> <Arrival_departure /> <Guest_type>OWN</ Guest_type > <Rate_Type>Rack</ Rate_Type& gt; <Task_type /> <Cleaning_levels /> <Arv_date>04/02/2016 </Arv_d ate> <Dpt_date>04/06/2016 </Dpt_d ate> <To_do_date /> <Special_requests>AL LERGY</ Special_re quests> <Next_arv_date>04/06 /2016</ Next_arv_d ate> <Next_guest_name>Joh n Test</Next_guest_name&g t; <Next_guest_cell_phone& gt;4332323 </Next_ guest_cell _phone> </Reservation_status> ; <Reservation_status diffgr:id='Reservation_sta tus2' msdata:rowOrder='1'> <Unit_id>2512243697& lt;/Unit_i d> <Arrival_departure /> <Guest_type>GRP</ Guest_type > <Rate_Type>Rack</ Rate_Type& gt; <Task_type /> <Cleaning_levels /> <Arv_date>04/01/2016 </Arv_d ate> <Dpt_date>04/04/2016 </Dpt_d ate> <To_do_date /> <Special_requests>E- ARRIVAL< ;/Special_ requests&g t; <Next_arv_date>04/08 /2016</ Next_arv_d ate> <Next_guest_name>Har vey Jones</Next_guest_name& gt; <Next_guest_cell_phone& gt;3105551 212</Ne xt_guest_c ell_phone& gt; </Reservation_status> ; <Reservation_status diffgr:id='Reservation_sta tus3' msdata:rowOrder='2'> <Unit_id>2515403106& lt;/Unit_i d> <Arrival_departure /> <Guest_type>TRAN< /Guest_typ e> <Rate_Type>Rack</ Rate_Type& gt; <Task_type /> <Cleaning_levels /> <Arv_date>04/06/2016 </Arv_d ate> <Dpt_date>04/13/2016 </Dpt_d ate> <To_do_date /> <Special_requests>E- TOWEL</ Special_re quests> <Next_guest_name /> </Reservation_status> ; <Reservation_status diffgr:id='Reservation_sta tus4' msdata:rowOrder='3'> <Unit_id>2512243708& lt;/Unit_i d> <Arrival_departure /> <Guest_type>TRAN< /Guest_typ e> <Rate_Type>Rack</ Rate_Type& gt; <Task_type /> <Cleaning_levels /> <Arv_date>04/01/2016 </Arv_d ate> <Dpt_date>04/08/2016 </Dpt_d ate> <To_do_date /> <Special_requests>E- Blanket< ;/Special_ requests&g t; <Next_arv_date>04/09 /2016</ Next_arv_d ate> <Next_guest_name>Har vey White</Next_guest_name& gt; <Next_guest_cell_phone& gt;5145528 789</Ne xt_guest_c ell_phone& gt; </Reservation_status> ; </DsStatusTracker> </diffgr:diffgram>
</string></XMLGetSta tusTracker InfoResult ></XMLGetS tatusTrack erInfoResp onse></soa p:Body></s oap:Envelo pe>
This is the response to a method they are calling "GetInfo" -
Response:
<?xml version="1.0" encoding="utf-8"?><soap:En
This is the response to a method they are calling "XMLGetInfo"
Response:
<?xml version="1.0" encoding="utf-8"?><soap:En
</string></XMLGetSta
Yes, I think the fact that they are sending a string representation of a PHP StdClass object is exactly the problem. The remote service creates the object, then they use var_dump() to create a string. That's what we are seeing here. Instead of using var_dump() they should use json_encode(). They will still get a string variable, but it will be a usable string -- one that can be requested by rwinnick's script and returned by the remote service.
Unfortunately there is no convenient way to take the output of var_dump() and turn it into a PHP object. A more promising approach might be to use var_export() but I would try JSON first since it is a standard for data interchange.
Unfortunately there is no convenient way to take the output of var_dump() and turn it into a PHP object. A more promising approach might be to use var_export() but I would try JSON first since it is a standard for data interchange.
ASKER
In the past have had no problems with this approach with other 3rd party folks using
simpleXMLElement or SimpleXML_Load_String to then be able to iterate through abstracting information needed. Ray has helped me in the past. Not sure what I'm missing this time. Thought I was getting better at this :-(
simpleXMLElement or SimpleXML_Load_String to then be able to iterate through abstracting information needed. Ray has helped me in the past. Not sure what I'm missing this time. Thought I was getting better at this :-(
ASKER
Hi Ray -
Unsure code snippet??
The site has changed drastically since last I visited -
Richard
Unsure code snippet??
The site has changed drastically since last I visited -
Richard
Sigh... This is an object lesson showing why most of the world has abandoned SOAP!
Try something like this.
http://iconoun.com/demo/temp_rwinnick.php
Try something like this.
http://iconoun.com/demo/temp_rwinnick.php
<?php // demo/temp_rwinnick.php
/**
* http://www.experts-exchange.com/questions/28936926/help-with-simple-xml-php.html#a41532140
*/
error_reporting(E_ALL);
echo '<pre>';
// TEST DATA SAMPLE FROM THE POST AT E-E
$xml = <<<EOD
<?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><GetStatusTrackerInfoResponse xmlns="http://iqwareinc.com/WebRes"><GetStatusTrackerInfoResult><StatusTracker><Unit_id>2515403106</Unit_id><Arrival_departure /><Guest_type>OWN</Guest_type><Rate_Type>Rack</Rate_Type><Task_type /><Cleaning_levels /><Arv_date>04/02/2016</Arv_date><Dpt_date>04/06/2016</Dpt_date><To_do_date /><Special_requests>ALLERGY</Special_requests><Next_arv_date>04/06/2016</Next_arv_date><Next_guest_name>John Test</Next_guest_name><Next_guest_cell_phone>4332323</Next_guest_cell_phone></StatusTracker><StatusTracker><Unit_id>2512243697</Unit_id><Arrival_departure /><Guest_type>GRP</Guest_type><Rate_Type>Rack</Rate_Type><Task_type /><Cleaning_levels /><Arv_date>04/01/2016</Arv_date><Dpt_date>04/04/2016</Dpt_date><To_do_date /><Special_requests>E-ARRIVAL</Special_requests><Next_arv_date>04/08/2016</Next_arv_date><Next_guest_name>Harvey Jones</Next_guest_name><Next_guest_cell_phone>3105551212</Next_guest_cell_phone></StatusTracker><StatusTracker><Unit_id>2515403106</Unit_id><Arrival_departure /><Guest_type>TRAN</Guest_type><Rate_Type>Rack</Rate_Type><Task_type /><Cleaning_levels /><Arv_date>04/06/2016</Arv_date><Dpt_date>04/13/2016</Dpt_date><To_do_date /><Special_requests>E-TOWEL</Special_requests><Next_arv_date /><Next_guest_name /><Next_guest_cell_phone /></StatusTracker><StatusTracker><Unit_id>2512243708</Unit_id><Arrival_departure /><Guest_type>TRAN</Guest_type><Rate_Type>Rack</Rate_Type><Task_type /><Cleaning_levels /><Arv_date>04/01/2016</Arv_date><Dpt_date>04/08/2016</Dpt_date><To_do_date /><Special_requests>E-Blanket</Special_requests><Next_arv_date>04/09/2016</Next_arv_date><Next_guest_name>Harvey White</Next_guest_name><Next_guest_cell_phone>5145528789</Next_guest_cell_phone></StatusTracker></GetStatusTrackerInfoResult></GetStatusTrackerInfoResponse></soap:Body></soap:Envelope>
EOD;
// REMOVE THE NAMESPACE INFORMATION
$new = MungXML($xml);
// CREATE THE OBJECT AND VISUALIZE ITS CONTENTS
$obj = SimpleXML_Load_String($new);
var_dump($obj);
// FUNCTION TO MUNG THE XML SO WE DO NOT HAVE TO DEAL WITH NAMESPACE
function mungXML($xml)
{
$obj = SimpleXML_Load_String($xml);
if ($obj === FALSE) return $xml;
// GET NAMESPACES, IF ANY
$nss = $obj->getNamespaces(TRUE);
if (empty($nss)) return $xml;
// CHANGE ns: INTO ns_
$nsm = array_keys($nss);
foreach ($nsm as $key)
{
// A REGULAR EXPRESSION TO MUNG THE XML
$rgx
= '#' // REGEX DELIMITER
. '(' // GROUP PATTERN 1
. '\<' // LOCATE A LEFT WICKET
. '/?' // MAYBE FOLLOWED BY A SLASH
. preg_quote($key) // THE NAMESPACE
. ')' // END GROUP PATTERN
. '(' // GROUP PATTERN 2
. ':{1}' // A COLON (EXACTLY ONE)
. ')' // END GROUP PATTERN
. '#' // REGEX DELIMITER
;
// INSERT THE UNDERSCORE INTO THE TAG NAME
$rep
= '$1' // BACKREFERENCE TO GROUP 1
. '_' // LITERAL UNDERSCORE IN PLACE OF GROUP 2
;
// PERFORM THE REPLACEMENT
$xml = preg_replace($rgx, $rep, $xml);
}
return $xml;
}
ASKER
Will do.
Will try your suggestion now -
Thanks
R
Will try your suggestion now -
Thanks
R
ASKER
Hi Ray -
Your example works fine -
However when I try to use the 'result' as the $xml input I get the 'needs string error' -
Here is the results
Warning: simplexml_load_string() expects parameter 1 to be string, object given in .............
Fatal error: Call to a member function getNamespaces() on a non-object in ..................
What a nightmare -
I just asked and the third party folks are using .net if that matters -
Re: you comment about folks not using soap what is a good alternative -
Just curious for the future -
Thanks
R
Your example works fine -
However when I try to use the 'result' as the $xml input I get the 'needs string error' -
Here is the results
<?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><XMLGetStatusTrackerInfoResponse xmlns="http://iqwareinc.com/WebRes"><XMLGetStatusTrackerInfoResult><?xml version='1.0' encoding='utf-8'?> <ReservationList xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>06/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243697</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>GRP</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>04/04/2016</Dpt_date> <To_do_date>04/04/2016</To_do_date> <Special_requests>E-ARRIVAL</Special_requests> <Next_arv_date>08/04/2016</Next_arv_date> <Next_guest_name>Harvey Jones</Next_guest_name> <Next_guest_cell_phone>3105551212</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>13/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>TE</Task_type> <Cleaning_levels>TE</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>10/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>05/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> </ReservationList></XMLGetStatusTrackerInfoResult></XMLGetStatusTrackerInfoResponse></soap:Body></soap:Envelope>
Here are the errorsWarning: simplexml_load_string() expects parameter 1 to be string, object given in .............
Fatal error: Call to a member function getNamespaces() on a non-object in ..................
What a nightmare -
I just asked and the third party folks are using .net if that matters -
Re: you comment about folks not using soap what is a good alternative -
Just curious for the future -
Thanks
R
Future alternative that everybody is choosing today: JSON.
This data set is a mess! Does the publisher have any documentation saying how to use it? It looks like nested XML inside XML, or some other oddity.
This data set is a mess! Does the publisher have any documentation saying how to use it? It looks like nested XML inside XML, or some other oddity.
This is not something you should need to do with an API. It should return a data string that is immediately useful, not something that has to be parsed and munged. But that aside, we can find the inner XML document now. It's an object containing a property named Reservation; Reservation is an array of 9 reservation objects.
http://iconoun.com/demo/temp_rwinnick.php
http://iconoun.com/demo/temp_rwinnick.php
<?php // demo/temp_rwinnick.php
/**
* http://www.experts-exchange.com/questions/28936926/help-with-simple-xml-php.html#a41532246
*/
error_reporting(E_ALL);
echo '<pre>';
// TEST DATA SAMPLE FROM THE POST AT E-E
$xml = <<<EOD
<?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><XMLGetStatusTrackerInfoResponse xmlns="http://iqwareinc.com/WebRes">
<XMLGetStatusTrackerInfoResult>
<?xml version='1.0' encoding='utf-8'?> <ReservationList xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<Reservation>
<Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels>
<Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>06/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests>
<Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name>
<Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure />
<Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels>
<Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests>
<Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation>
<Reservation> <Unit_id>2512243697</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>GRP</Guest_type> <Rate_Type>Rack</Rate_Type>
<Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>04/04/2016</Dpt_date> <To_do_date>04/04/2016</To_do_date>
<Special_requests>E-ARRIVAL</Special_requests> <Next_arv_date>08/04/2016</Next_arv_date> <Next_guest_name>Harvey Jones</Next_guest_name> <Next_guest_cell_phone>3105551212</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>13/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>TE</Task_type> <Cleaning_levels>TE</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>10/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>05/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> </ReservationList>
</XMLGetStatusTrackerInfoResult></XMLGetStatusTrackerInfoResponse></soap:Body></soap:Envelope>
EOD;
// THE TEST DATA APPEARS TO NEST XML INSIDE OF XML - ISOLATE THE INNER XML
$sig = '<XMLGetStatusTrackerInfoResult>';
$arr = explode($sig, $xml);
$xml = $arr[1];
$sig = '</XMLGetStatusTrackerInfoResult>';
$arr = explode($sig, $xml);
$xml = $arr[0];
// THE TEST DATA APPEARS TO BE FULL OF HTML ENTITIES
$xml = html_entity_decode($xml);
$xml = trim($xml);
// REMOVE THE NAMESPACE INFORMATION
$new = MungXML($xml);
// CREATE THE OBJECT AND VISUALIZE ITS CONTENTS
$obj = SimpleXML_Load_String($new);
var_dump($obj);
// FUNCTION TO MUNG THE XML SO WE DO NOT HAVE TO DEAL WITH NAMESPACE
function mungXML($xml)
{
$obj = SimpleXML_Load_String($xml);
if ($obj === FALSE) return $xml;
// GET NAMESPACES, IF ANY
$nss = $obj->getNamespaces(TRUE);
if (empty($nss)) return $xml;
// CHANGE ns: INTO ns_
$nsm = array_keys($nss);
foreach ($nsm as $key)
{
// A REGULAR EXPRESSION TO MUNG THE XML
$rgx
= '#' // REGEX DELIMITER
. '(' // GROUP PATTERN 1
. '\<' // LOCATE A LEFT WICKET
. '/?' // MAYBE FOLLOWED BY A SLASH
. preg_quote($key) // THE NAMESPACE
. ')' // END GROUP PATTERN
. '(' // GROUP PATTERN 2
. ':{1}' // A COLON (EXACTLY ONE)
. ')' // END GROUP PATTERN
. '#' // REGEX DELIMITER
;
// INSERT THE UNDERSCORE INTO THE TAG NAME
$rep
= '$1' // BACKREFERENCE TO GROUP 1
. '_' // LITERAL UNDERSCORE IN PLACE OF GROUP 2
;
// PERFORM THE REPLACEMENT
$xml = preg_replace($rgx, $rep, $xml);
}
return $xml;
}
ASKER
Again tried to substitute actual reponse for $xml got a warning and bool (false)
Here it is:
Here it is:
Response:
<?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><XMLGetStatusTrackerInfoResponse xmlns="http://iqwareinc.com/WebRes"><XMLGetStatusTrackerInfoResult><?xml version='1.0' encoding='utf-8'?> <ReservationList xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>06/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243697</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>GRP</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>04/04/2016</Dpt_date> <To_do_date>04/04/2016</To_do_date> <Special_requests>E-ARRIVAL</Special_requests> <Next_arv_date>08/04/2016</Next_arv_date> <Next_guest_name>Harvey Jones</Next_guest_name> <Next_guest_cell_phone>3105551212</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>13/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>TE</Task_type> <Cleaning_levels>TE</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>10/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>05/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> </ReservationList></XMLGetStatusTrackerInfoResult></XMLGetStatusTrackerInfoResponse></soap:Body></soap:Envelope>
Warning: explode() expects parameter 2 to be string, object given in line 63 (note 63 is: $arr = explode($sig, $xml);)
bool(false)
Please post three things for us:
1. The link to the documentation that describes the API;
2. The URL that you're using to get this information;
3. The PHP script that you're using to read from the URL of the API.
I do not get any error when I use the XML string above with this script.
Thanks!
1. The link to the documentation that describes the API;
2. The URL that you're using to get this information;
3. The PHP script that you're using to read from the URL of the API.
I do not get any error when I use the XML string above with this script.
Thanks!
<?php // demo/temp_rwinnick.php
/**
* http://www.experts-exchange.com/questions/28936926/help-with-simple-xml-php.html#a41532306
*/
error_reporting(E_ALL);
echo '<pre>';
// TEST DATA SAMPLE FROM THE POST AT E-E
$xml = <<<EOD
<?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><XMLGetStatusTrackerInfoResponse xmlns="http://iqwareinc.com/WebRes"><XMLGetStatusTrackerInfoResult><?xml version='1.0' encoding='utf-8'?> <ReservationList xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>06/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>OWN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>02/04/2016</Arv_date> <Dpt_date>06/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>ALLERGY</Special_requests> <Next_arv_date>06/04/2016</Next_arv_date> <Next_guest_name>John Test</Next_guest_name> <Next_guest_cell_phone>4332323</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243697</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>GRP</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>04/04/2016</Dpt_date> <To_do_date>04/04/2016</To_do_date> <Special_requests>E-ARRIVAL</Special_requests> <Next_arv_date>08/04/2016</Next_arv_date> <Next_guest_name>Harvey Jones</Next_guest_name> <Next_guest_cell_phone>3105551212</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>13/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>TE</Task_type> <Cleaning_levels>TE</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2515403106</Unit_id> <Arrival_departure /> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>06/04/2016</Arv_date> <Dpt_date>13/04/2016</Dpt_date> <To_do_date>10/04/2016</To_do_date> <Special_requests>E-TOWEL- E-PAPER</Special_requests> <Next_arv_date /> <Next_guest_name /> <Next_guest_cell_phone /> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>GDC</Task_type> <Cleaning_levels>GDC</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>08/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>MID</Task_type> <Cleaning_levels>MID</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>03/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> <Reservation> <Unit_id>2512243708</Unit_id> <Arrival_departure>arrival</Arrival_departure> <Guest_type>TRAN</Guest_type> <Rate_Type>Rack</Rate_Type> <Task_type>T&amp;T</Task_type> <Cleaning_levels>T&amp;T</Cleaning_levels> <Arv_date>01/04/2016</Arv_date> <Dpt_date>08/04/2016</Dpt_date> <To_do_date>05/04/2016</To_do_date> <Special_requests>E-Blanket- LOUNGE</Special_requests> <Next_arv_date>09/04/2016</Next_arv_date> <Next_guest_name>Harvey White</Next_guest_name> <Next_guest_cell_phone>5145528789</Next_guest_cell_phone> </Reservation> </ReservationList></XMLGetStatusTrackerInfoResult></XMLGetStatusTrackerInfoResponse></soap:Body></soap:Envelope>
EOD;
// THE TEST DATA APPEARS TO NEST XML INSIDE OF XML - ISOLATE THE INNER XML
$sig = '<XMLGetStatusTrackerInfoResult>';
$arr = explode($sig, $xml);
$xml = $arr[1];
$sig = '</XMLGetStatusTrackerInfoResult>';
$arr = explode($sig, $xml);
$xml = $arr[0];
// THE TEST DATA APPEARS TO BE FULL OF HTML ENTITIES
$xml = html_entity_decode($xml);
$xml = trim($xml);
// REMOVE THE NAMESPACE INFORMATION
$new = MungXML($xml);
// CREATE THE OBJECT AND VISUALIZE ITS CONTENTS
$obj = SimpleXML_Load_String($new);
var_dump($obj);
// FUNCTION TO MUNG THE XML SO WE DO NOT HAVE TO DEAL WITH NAMESPACE
function mungXML($xml)
{
$obj = SimpleXML_Load_String($xml);
if ($obj === FALSE) return $xml;
// GET NAMESPACES, IF ANY
$nss = $obj->getNamespaces(TRUE);
if (empty($nss)) return $xml;
// CHANGE ns: INTO ns_
$nsm = array_keys($nss);
foreach ($nsm as $key)
{
// A REGULAR EXPRESSION TO MUNG THE XML
$rgx
= '#' // REGEX DELIMITER
. '(' // GROUP PATTERN 1
. '\<' // LOCATE A LEFT WICKET
. '/?' // MAYBE FOLLOWED BY A SLASH
. preg_quote($key) // THE NAMESPACE
. ')' // END GROUP PATTERN
. '(' // GROUP PATTERN 2
. ':{1}' // A COLON (EXACTLY ONE)
. ')' // END GROUP PATTERN
. '#' // REGEX DELIMITER
;
// INSERT THE UNDERSCORE INTO THE TAG NAME
$rep
= '$1' // BACKREFERENCE TO GROUP 1
. '_' // LITERAL UNDERSCORE IN PLACE OF GROUP 2
;
// PERFORM THE REPLACEMENT
$xml = preg_replace($rgx, $rep, $xml);
}
return $xml;
}
ASKER
I have put together what I have in the attached documentxml_documentation_ray.docx
Does this service offer a RESTful API? They should since it appears that they are wrapping the true response document inside CDATA tags. If we can get them to just send us the information we need, not all the other SOAP overhead, it will be easier to get this to work right.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ray -
Sorry yes for pass and user -
However in the interim based on your hint about using JSON I have figured out a work around to get to the info using NUSOAP and JSON -
Here is a 'snippet' using the result of the NUSOAP call
$jsonOBJ = json_decode (json_encode ($result), FALSE);
//FORMAT XML::
$xml = simplexml_load_string($jso nOBJ->XMLG etStatusTr ackerInfoR esult);
now simplexml works and I can iterate through the result as you have shown me in the past
I am going to award the points to you for your help
Thanks again as always you guys are great!
Richard
Sorry yes for pass and user -
However in the interim based on your hint about using JSON I have figured out a work around to get to the info using NUSOAP and JSON -
Here is a 'snippet' using the result of the NUSOAP call
$jsonOBJ = json_decode (json_encode ($result), FALSE);
//FORMAT XML::
$xml = simplexml_load_string($jso
now simplexml works and I can iterate through the result as you have shown me in the past
I am going to award the points to you for your help
Thanks again as always you guys are great!
Richard
ASKER
provided insight to arrive at a solution -
Great - glad it's working out :-)