Probably easier if I start with some background info. I have a property portal website and normally an agent would provide me with a link to an xml file containing details of their properties. I set up a cron job and collect their xml file from the url and update our database. Easy.
What I want to do is capture the data and save it (Basically everything between <lots></lots>). I can then parse it and update our database.
After hours of trawling the internet I have got this far
I know I need to put something in $params but have no idea what. If I leave $params empty it throws an error:
PHP Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null etc and it highlights the line $result=
I just cannot work out what to put for $params so that I can capture all the xml data.
I've been back to krier.fr and asked for help/examples and been told they can't help.
PHPSOAP ProtocolWeb Services
Last Comment
Ray Paseur
8/22/2022 - Mon
Ray Paseur
There's probably a way around this dilemma, and the first thing you should ask krier.fr if they offer a RESTful interface to the data set. A RESTful API is much easier to use because it simply responds with useful data and does not force you to guess what is going on in the other server. This is one of the main reasons that most major internet companies abandoned SOAP about a decade ago, and almost nobody uses SOAP any more.
If they offer a RESTful API, you're (almost) home free.
If they don't then we have a little more work to do. It would be helpful to see a true and complete example of the SOAP string posted above, but hopefully this will help you get started. https://iconoun.com/demo/temp_fionafenton.php
<?php // demo/temp_fionafenton.php/** * https://www.experts-exchange.com/questions/28974256/PHP-and-SOAP-Woes.html */ini_set('display_errors', TRUE);error_reporting(E_ALL);echo '<pre>';// THE SOAP RESPONSE STRING SAMPLE FROM E-E$soap = <<<EOS<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetXmlDataResponse xmlns="http://tempuri.org/"><GetXmlDataResult><lots><lot>THIS IS FROM LOT #1</lot><lot>THIS IS FROM LOT #2</lot></lots></GetXmlDataResult></GetXmlDataResponse></soap:Body></soap:Envelope>EOS;// MUNG THE SOAP RESPONSE SO WE CAN PARSE IT EASILY$mung = mungXML($soap);// PARSE THE XML DOCUMENT$objs = SimpleXML_Load_String($mung);$lots = $objs->soap_Body->GetXmlDataResponse->GetXmlDataResult->lots;// USE AN ITERATOR TO ACCESS THE DATA INSIDE THE OBJECTforeach ($lots->lot as $thing){ echo PHP_EOL . trim($thing);}// A FUNCTION TO MUNG THE XML SO WE DO NOT HAVE TO DEAL WITH NAMESPACEfunction 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;}
Hi Ray
Having seen your comments in other questions I have already asked them if there is a REST alternative but have yet to hear back from them.
I'm not sure that you've fully understood my problem? It is getting the soap response that I'm having trouble with. Once I've got it and saved it I can parse it. At the moment I can only get the response by going to soapclient.com web page above and manually entering login credentials and then copying and pasting the output.
What I want to eventually do is set up a cron to do it. I should be able to achieve this using
Then get my email address from the information there.
Then send me the credentials you've used to get the the response information from the soapclient.com web site. I need the complete URL(s) and any login credentials you've used to get the browser to "login" to the site.
I believe that we can read this site in an automated manner and parse the response. This is not the ultimate and ideal solution but it will buy you time until you can get the krier.fr people to respond to your request for help. Worth a try, at least.
If they offer a RESTful API, you're (almost) home free.
If they don't then we have a little more work to do. It would be helpful to see a true and complete example of the SOAP string posted above, but hopefully this will help you get started.
https://iconoun.com/demo/temp_fionafenton.php
Open in new window
Outputs:Open in new window