chuckjones Posted June 25, 2009 Share Posted June 25, 2009 Hi - I'm having issues trying to setup a nuSOAP client that will connect to a .NET web service. I can connect fine, the issue I have is with handling the resulting XML / array, what ever it is that's coming out. Here's the code: <?php /* * $Id: wsdlclient1.php,v 1.3 2007/11/06 14:48:48 snichol Exp $ * * WSDL client sample. * * Service: WSDL * Payload: document/literal * Transport: http * Authentication: none */ require_once ('lib/nusoap.php'); $wsdl = "http://dev.XXX.XXX/XXX.asmx?wsdl"; $params = array('XXX' => '204'); $namespace = "http://www.w3.org/2001/XMLSchema"; $soapAction = "http://tempuri.org/GetCityList"; $client = new nusoap_client($wsdl); $result = $client->call('GetCityList', $params, $namespace, $soapAction); //echo("<pre>". $client->response. "</pre>"); //echo $result["GetCityListResult"]; ?> You can see what combo's I've played with in the commented out echos. The GetCityListResult will yield an "array" but I have no idea how to iterate through it to get the fields that I need? Thanks for your help, Rob Quote Link to comment Share on other sites More sharing options...
dzelenika Posted June 25, 2009 Share Posted June 25, 2009 try print_r($result); I don't use nuSoap but PHP's Soap extension which looks similar <?php $client = SoapClient("some.wsdl", array('trace' => 1)); $result = $client->SomeFunction(); echo "REsponse:\n" . $client->__getLastResponse() . "\n"; ?> If you want to see xml with response probably you should set trace to ON like in upper example. TIP: look at the source. Maybe $client->response is echoed, but you cant see it in browser because is xml document embedded in HTML. Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 Good start, a step closer. print_r ($result); Gave the following results. Now with that output, trying to get that array with the elements in it. Right where "[0] => Array" starts, that's the output that I'm looking to iterate through. Tried print_r ($result['table']); print_r ($result['NewDataSet']); print_r ($result[1]); All give me "Notice: Undefined index: NewDataSet" Thanks for the help, ideas? Array ( [schema] => Array ( [element] => Array ( [complexType] => Array ( [choice] => Array ( [element] => Array ( [complexType] => Array ( [sequence] => Array ( [element] => Array ( [0] => Array ( [!name] => CityID [!minOccurs] => 0 ) [1] => Array ( [!name] => StateCity [!minOccurs] => 0 ) ) ) ) [!name] => Table ) [!minOccurs] => 0 [!maxOccurs] => unbounded ) ) [!name] => NewDataSet [!msdata:IsDataSet] => true [!msdata:MainDataTable] => Table [!msdata:Locale] => ) [!id] => NewDataSet ) [diffgram] => Array ( [NewDataSet] => Array ( [table][tr][td] => Array ( [0] => Array ( [CityID] => 344 [stateCity] => AK - Anchorage [!diffgr:id] => Table1 [!msdata:rowOrder] => 0 ) [1] => Array ( [CityID] => 346 [stateCity] => AK - Fairbanks [!diffgr:id] => Table2 [!msdata:rowOrder] => 1 ) [2] => Array ( [CityID] => 347 [stateCity] => AK - Juneau [!diffgr:id] => Table3 [!msdata:rowOrder] => 2 ) Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 Please, help. Stuck? Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 It looks like you have an array inside of an array so to get to it you need something like this. <?php print_r($result[diffgram][NewDataSet]); ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 Damn it. here's what perplexes me about this. Using: echo ($result); get "Array" as the output. Go with this: for($i = 0; $i < count($result); $i++) { echo $result[$i]; } and get Notice: Undefined offset: 0 Notice: Undefined offset: 1 in ... Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 Try this instead. <?php foreach($result as $key=>$value) { echo $key.' = '.$value; } ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 foreach($result as $key=>$value) { echo $key.' = '.$value; } Output: schema = Array diffgram = Array print_r($result[diffgram][NewDataSet]); Output: Use of undefined constant diffgram - assumed 'diffgram' in Notice: Use of undefined constant NewDataSet - assumed 'NewDataSet' in Array ( [Table] => Array ( [0] => Array ( [CityID] => 344 [stateCity] => AK - Anchorage [!diffgr:id] => Table1 [!msdata:rowOrder] => 0 ) [1] => Array ( [CityID] => 346 [stateCity] => AK - Fairbanks [!diffgr:id] => Table2 [!msdata:rowOrder] => 1 ) [2] => Array ( [CityID] => 347 [stateCity] => AK - Juneau [!diffgr:id] => Table3 [!msdata:rowOrder] => 2 ) [3] => Array ( [CityID] => 331 [stateCity] => AL - Anniston [!diffgr:id] => Table4 [!msdata:rowOrder] => 3 ) [4] => Array ( [CityID] => 20 [stateCity] => AL - Birmingham [!diffgr:id] => Table5 [!msdata:rowOrder] => 4 ) Thanks! Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 This should resolve the error, sorry about that. <?php print_r($result['diffgram']['NewDataSet']); ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 Holy S! Well, I'm a step away from sleeping now after days of pain. Believe me there were 400 versions of my code. Just broke down the simplest form for you. Here's what comes out of it. 95% there. Now how do I get the CityID and the StateCity values out in an iterative loop... so I can populate dropdowns, etc. Thanks again. Array ( [Table] => Array ( [0] => Array ( [CityID] => 344 [stateCity] => AK - Anchorage [!diffgr:id] => Table1 [!msdata:rowOrder] => 0 ) [1] => Array ( [CityID] => 346 [stateCity] => AK - Fairbanks [!diffgr:id] => Table2 [!msdata:rowOrder] => 1 ) [2] => Array ( [CityID] => 347 [stateCity] => AK - Juneau [!diffgr:id] => Table3 [!msdata:rowOrder] => 2 ) [3] => Array ( [CityID] => 331 [stateCity] => AL - Anniston [!diffgr:id] => Table4 [!msdata:rowOrder] => 3 ) [4] => Array ( [CityID] => 20 [stateCity] => AL - Birmingham [!diffgr:id] => Table5 [!msdata:rowOrder] => 4 ) [5] => Array ( [CityID] => 86 [stateCity] => AL - Decatur [!diffgr:id] => Table6 [!msdata:rowOrder] => 5 ) Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 OK this is not tested, but I believe my logic to be correct. Not sure what way you want to go now, but now in the two new arrays each key will match as a pair for you to use as you need. <?php $cityIDs=array(); $StateCities=array(); foreach($result['diffgram']['NewDataSet']['Table'] as $array){ $cityIDs[]=$array['CityID']; $StateCities[]=$array['StateCity']; } ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 25, 2009 Author Share Posted June 25, 2009 This worked! Really thrilled, thank you much. HOLY S what a chore this became for something that is pretty straight forward. Will try to integrate all of my code today and then see if I have more hiccups. What you did for me today is beyond appreciated! Used to .NET where we'd get a data table... handling things as an array is different for me.... $cityIDs=array(); $StateCities=array(); foreach($result['diffgram']['NewDataSet']['Table'] as $array){ $cityIDs[]=$array['CityID']; $StateCities[]=$array['StateCity']; } foreach ($cityIDs As $cityID) { echo($cityID). "<br>"; } Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 No Problem, I understand that it always help to have a fresh set of eyes. Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 29, 2009 Author Share Posted June 29, 2009 Hey - One question. The Array names keep changing as they come out.... see below: The "_x0037_6" was "_x0037_4" from the web service this AM? foreach($result['diffgram']['NewDataSet']['_x0037_6'] as $array) { $TopVotes[]=$array['Votes']; } Is there a way to reference this non-explicitly? Tried $result['diffgram']['NewDataSet'][0] That didn't work. Thanks Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 I am kind of lost as to where you are going with this now. But I think you are looking for: <?php foreach($result['diffgram']['NewDataSet'][] as $array) { $TopVotes[]=$array['Votes']; } ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 29, 2009 Author Share Posted June 29, 2009 yeah, that was my thought too..... "Fatal error: Cannot use [] for reading" with that. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 Did the below give you an error to? <?php foreach($result['diffgram']['NewDataSet'][0] as $array) { $TopVotes[]=$array['Votes']; } ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 29, 2009 Author Share Posted June 29, 2009 "Notice: Undefined offset: 0 in " ...... Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 To help me understand can you post the results for this, then we will go from there. I think possibly this could be binary or an actually memory location, which may mean this is being passed by reference. <?php foreach($result['diffgram']['NewDataSet'] as $array) { print_r($array); } ?> Quote Link to comment Share on other sites More sharing options...
chuckjones Posted June 29, 2009 Author Share Posted June 29, 2009 Array ( [0] => Array ( [Votes] => 11 [CityState] => Chico, CA [Rank] => 1 [!diffgr:id] => 861 [!msdata:rowOrder] => 0 [!diffgr:hasChanges] => modified ) [1] => Array ( [Votes] => 5 [CityState] => Anchorage, AK [Rank] => 2 [!diffgr:id] => 862 [!msdata:rowOrder] => 1 [!diffgr:hasChanges] => modified ) [2] => Array ( [Votes] => 5 [CityState] => Los Angeles, CA [Rank] => 3 [!diffgr:id] => 863 [!msdata:rowOrder] => 2 [!diffgr:hasChanges] => modified ) ) Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 Ok my next question is how were you getting this value ''_x0037_6'' as the key for the array? What were you using it for, where is it? What value are you looking to get? Quote Link to comment 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.