1

Re: Working PHP SpeciesList

Can anybody show me some code for a working PHP SpeciesList request?

2

Re: Working PHP SpeciesList

Information on using the NBN Gateway Web Services can be found via the web services link from the NBN web site (http://data.nbn.org.uk/library/webservices/wsIndex.jsp). From here you should find the information on the specieslist web service you are looking for. Example PHP code may be found at http://data.nbn.org.uk/library/webservices/wsSpeciesListPHP.jsp for example

Best wishes
Graham French
NBN Technical Liaison Officer

3

Re: Working PHP SpeciesList

Hi Graham

The problem is that all the examples at http://data.nbn.org.uk/library/webservices/wsGroupList4.jsp seem to be broken. I have agreed to send to Ed the code I use for http://nesbrec.org/thesaurus2.php - which does work but is a work around.

Cheers

Nick

(ePlanning Project Manager) Aberdeenshire Council

4

Re: Working PHP SpeciesList

I agree - and have posted about this awhile ago. No sense in having examples if they don't work. I'd like to see your working code if possible, Thanks.

5

Re: Working PHP SpeciesList

I had some examples using PHP that were working 18 months ago, but on revisiting the topic today found they have biodegraded.

The examples to which we are directed at http://www.marlin.ac.uk/NBNservices/examples.php don't seem to work anymore either, nor other NBN-sourced examples, such as the one at http://data.nbn.org.uk/library/webservices/php/ws-gridmap.php.

Are there any working examples using PHP to which I can refer please?

Is using PHP still a valid approach since existing implementations no longer work?

Regards, Keith

6

Re: Working PHP SpeciesList

The php examples on the MarLIN site were done for the first release of the web services, and haven't been updated since, however the request and response are still working fine (ie the request returns an xml file).
The broken bit is how the php interacts with the returned XML.  It looks like that's just a question of cleaning up the returned XML so simpleXML (http://php.net/manual/en/book.simplexml.php) can interact with it.
Cheers
Dan

7 (edited by kbalmer 30-03-2010 21:09:00)

Re: Working PHP SpeciesList

Thank you Dan for the encouragement I needed to keep trying. This evening I was able to get some sense from the example at http://www.marlin.ac.uk/NBNservices/downloads/GetGridMap.zip by replacing the function fixupxml with the following:
 
function fixupxml($xml) {
    $pos = strpos($xml, '<SOAP-ENV:Body');   // Find the start of the <SOAP-ENV:Body tag
    $xml = substr($xml,$pos);                // Discard everything before it
    $pos = strpos($xml, '>');                // Find the close of the <SOAP-ENV:Body tag
    $xml = substr($xml,$pos+1);              // Discard the remainder of the SOAP-ENV:Body tag
    $pos = strpos($xml, '</SOAP-ENV:Body>'); // Find the start of the </SOAP-ENV:Body> tag
    $xml = substr($xml,0,$pos);              // Discard the </SOAP-ENV:Body> tag and everything after it
    $xml = '<?xml version="1.0" encoding="utf-8"?>'.$xml; // Add the missing xml header
    return $xml;
  }

I also needed to replace
  $client = new soapclient(etc...)
with
  $client = new nusoap_client(etc...)
(This is to avoid a function name conflict in PHP5 which introduced its own function called soapclient. Make sure the version of SOAP you are using has this fix. I used nusoap-0.7.3)

I also needed to replace
  foreach ($obj->DatasetSummary as $DataSet)
with
  foreach ($obj->DatasetSummaryList->DatasetSummary as $DataSet)
(I don't know if there has been a data structure change that required this?)

Hope this helps anyone else that may be trying to use PHP/SOAP.

Regards, Keith

8

Re: Working PHP SpeciesList

Keith,

That's great you got it all working, I've updated the MarLIN examples and the downloads so hopefully they will help others.

Cheers
Dan