CREATE OR REPLACE FUNCTION outils.eu_nomen_taxa_code("scientific_name" text) RETURNS text AS $BODY$ import urllib2; import httplib; FROM urllib import urlencode FROM urllib2 import Request, urlopen # définition de l'URL du service url = 'http://www.eu-nomen.eu/portal/soap.php' # les données SOAP à poster au service postdata='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header/><soap:Body><getGUID xmlns="http://PESI/v0.1"><scientificname>'+scientific_name+'</scientificname></getGUID><soap:Fault/></soap:Body></soap:Envelope>' # l'entête headers = {'Content-Type': 'application/soap+xml; charset=utf-8','Content-Type': 'text/xml; charset=utf-8','Content-Length': str(len(postdata))} req = Request(url, postdata, headers) reponse = urlopen(req) text = reponse.READ() rv = plpy.execute("SELECT ((xpath('//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getGUIDResponse/return/text()', '"+text+"'::xml, ARRAY[ARRAY['SOAP-ENV','http://schemas.xmlsoap.org/soap/envelope/'],ARRAY['SOAP-ENC','http://schemas.xmlsoap.org/soap/encoding/'],ARRAY['xsd','http://www.w3.org/2001/XMLSchema'],ARRAY['xsi','http://www.w3.org/2001/XMLSchema-instance'],ARRAY['ns1','http://PESI/v0.1']]))[1])::text AS code_taxon") eu_nomen_code = rv[0]['code_taxon'] RETURN eu_nomen_code RETURN text $BODY$ LANGUAGE plpythonu VOLATILE COST 100; ALTER FUNCTION outils.eu_nomen_taxa_code("scientific_name" text) OWNER TO dba; COMMENT ON FUNCTION outils.eu_nomen_taxa_code("scientific_name" text) IS 'Retourne le code européen d''un taxon dont le nom d''espèce (sans auteur est passé en paramètre). Un grand merci à Dorian pour son micro cours sur SOAP!'
SELECT outils.eu_nomen_taxa_code('passer domestcus')
Retourne : urn:lsid:faunaeur.org:taxname:97437