Asked  9 Months ago    Answers:  5   Viewed   116 times

I want to convert a soap xml response and store it in a database. Here is the XML that I have.

<ENV:Envelope xmlns:ENV="" xmlns:ns1="">
               <Address1>example2, example2 </Address1>
               <Address2>example2, example2 </Address2>

I get this soap response from the server. I want to convert this to a array and store it in database. What should I do? I know the answer might be pretty straight forward, but hey, am a newbie :D

Would really appreciate any help I get.

Thank you in anticipation.




The best solution would be to use PHP's SoapClient class to do the call which will return you an object and then converting this object to an array, like so:

$client = new SoapClient("http://localhost/code/soap.wsdl");

// Soap call with HelloWorld() method
$something =  $client->HelloWorld(array('option1' => 'attribute1'));

// Convert object to array
$array = (array)$something;


Which you can then store in the database.

Wednesday, March 31, 2021
answered 9 Months ago

PHP's SoapClient has what is called "WSDL mode", where when you give it the URL for the WSDL, it downloads that WSDL, and extracts the real end point URL from the WSDL.

Java's SOAPConnection does not have a "WSDL mode", so you need to provide the real end point URL to the call() method, not the WSDL URL.

If you don't know the real end point URL, do what SoapClient does, download the WSDL yourself and look at it. The end point URL will be at the end.

From example WSDL:


  <service name="EndorsementSearchService">
    <documentation> Endorsement Service</documentation> 
    <port name="GetEndorsingBoarderPort"
      <soap:address location=""/>


Here the real end point URL is:

Wednesday, March 31, 2021
answered 9 Months ago

Remove the whitespace before <?xml and then it works. If you can't, maybe you can alter/extend the nusoap class to trim the response before interpretation. Most likely the extra whitespace comes from some accidental whitespace outside the <?php & ?> tags.

Friday, May 28, 2021
answered 7 Months ago

The real reason is normalisation, and you will break the first normalform by doing it.

However, there are many cases in which a breach of the normal forms could be considered. How many fields are you dealing with and are they all booleans?

Storing an array serialized as a string in your database will have the following disadvantages (among others):

  • When you need to update your settings you must first extract the current settings from the database, unserialize the array, change the array, serialize the array and update the data in the table.
  • When searching, you will not be able to just ask the database whether a given user (or a set of users) has a given setting disabled or enabled, thus you won't have any chances of searching.

Instead, you should really consider the option of creating another table with the records you need as a one-to-many relation from your other table. Thus you won't have 30 empty fields, but instead you can just have a row for each option that deviates from the default (note that this option has some disadvantages aswell, for example if you change the default).

In sum: I think you should avoid serializing arrays and putting them into the databases, at least if you care just a tiny bit about the aforementioned disadvantages.

Saturday, May 29, 2021
answered 7 Months ago

If anyone should be interested, i have provided the correct answer:

$soapUrl = "";

$xml_post_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12=""><soap12:Body><SearchCollectionPoint xmlns=""><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvÅ gen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';

$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch); 

$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);

$parser = simplexml_load_string($response2);
Wednesday, August 11, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :