[tdwg-tapir] error in tapir specification?

Renato De Giovanni renato at cria.org.br
Tue Jul 17 15:40:50 CEST 2007

Hi Wouter,

The specification is correct in the KVP examples, but other related 
parts need to be updated. I really hope I can find some time to 
update the specification during the next days. One of the pending 
changes will restrict content-type in POST requests to "application/x-
www-form-urlencoded" which makes it possible to extract all 
parameters from raw post data when necessary.

You're right that QUERY_STRING should also be available, but isn't 
this variable part of the CGI spec? 
I would be interested to know which web servers don't support this 
variable so that I can update TapirLink documentation and warn users 
about the limitation.

A couple of months ago TapirLink was not working with multiple 
concepts in KVP inventory requests, but now it should work (current 
code in Subversion, which should soon be part of a new release).

It's a pity that PHP doesn't handle well multiple parameters with the 
same name without using the square brackets trick. But you can also 
use the code below to get all parameters correctly.

Hope this helps,

// Alternative code to read query parameters in PHP

function _ParseQueryString( )
    $parameters = array();

    // See if there is any raw post
    $raw_post = '';

    if ( $fp = fopen('php://input', 'r') )
        while ( $data = fread($fp, 4096) )
            $raw_post .= $data;

        // raise an error here...

    // Concatenate query string and raw post before splitting
    $raw_input_items = split('&', 

    foreach ( $raw_input_items as $input_item )
        // split into name/value pair
        if ( $input_item != '' )
            $item = split('=', $input_item);

            $key = urldecode($item[0]);

            $value = (empty( $item[1] )) ? '' : urldecode($item[1]);

            if ( ! isset($parameters[$key]) )
                $parameters[$key] = $value;
            elseif ( ! is_array($parameters[$key]) )
                $first = $parameters[$key];
                $parameters[$key] = array();
                $parameters[$key][]= $first;
                $parameters[$key][]= $value;
                $parameters[$key][]= $value;

    return $parameters;

} // end of function _ParseQueryString

On 17 Jul 2007 at 12:11, Wouter Addink wrote:
> Hi Donald, 
> It is true that it depends on the processing software, but I think it 
> is not standard behavior and therefore I would not recommend it. It 
> is also implemented differently in Tapirlink. The reason is that 
> Tapirlink uses PHP and inPHP superglobals ($_GET or 
> $_REQUEST)return only he last kvp parameter if there are more with 
> the same name. An alternative could be to get the wholequery 
> stingwith a server variable ($_SERVER[QUERY_STRING])and to parse 
> the parameters with a regex, but that sounds not very attractive to 
> me, as it depends on the used webserver if this variable is available 
> and returned correctly.
>     ----- Original Message ----- 
>     From: Donald Hobern 
>     To: Wouter Addink 
>     Cc: tdwg-tapir at lists.tdwg.org 
>     Sent: Tuesday, July 17, 2007 11:54 AM
>     Subject: Re: [tdwg-tapir] error in tapir specification
>     Surely it depends on how the software processes the parameters. The 
>     GBIF data portal has adopted precisely this pattern (no square 
>     brackets) to allow users to specify a set of alternative values for 
>     many of the filters on the occurrence web search. The JSP receives 
>     the parameters fine.
>     Donald
>     Wouter Addink wrote: 
>     Hi,
>     I think there is an error in the KVP Inventory examples in the Tapir 
>     specification doc.
>     Examples like 
> http://example.net/tapir.cgi?op=inventory&concept=http://example.net/s
> chema1/Country& concept=http://example.net/schema1/Genus 
>     cannot be implemented I think, because concept will not be treated as 
>     an array here and only the last concept would be returned.
>     this would work:
>     http://example.net/tapir.cgi?op=inventory&concept[]=http://example.net
>     /schema1/Country& concept[]=http://example.net/schema1/Genus 
>     regards,
>     Wouter Addink

More information about the tdwg-tag mailing list