Query Results Formatter

## Query Results Formatter Query Results Formatter — Query results formatted into a syntax. |

## Synopsis

    int         rasqal_query_results_formats_enumerate
                                                (unsigned int counter,
                                                 const char **name,
                                                 const char **label,
                                                 unsigned char **uri_string);
    typedef     rasqal_query_results_formatter;
    rasqal_query_results_formatter* rasqal_new_query_results_formatter
                                                (const char *name,
                                                 raptor_uri *uri);
    void        rasqal_free_query_results_formatter
                                                (rasqal_query_results_formatter *formatter);
    int         rasqal_query_results_formatter_write
                                                (raptor_iostream *iostr,
                                                 rasqal_query_results_formatter *formatter,
                                                 rasqal_query_results *results,
                                                 raptor_uri *base_uri);

## Description

Variable bindings and boolean query results can be formatted into different syntaxes such as SPARQL Query Results Format or JSON. The rasqal_query_results_formatter class allows choosing a formatter for a particular syntax and writing the syntax to a raptor_iostream which allows turning the syntax into a string, writing to a file handle or other custom destination.

## Details

### rasqal_query_results_formats_enumerate ()

    int         rasqal_query_results_formats_enumerate
                                                (unsigned int counter,
                                                 const char **name,
                                                 const char **label,
                                                 unsigned char **uri_string);

Get information on query result syntaxes.

The current list of format names/URI is given below however the results of this function will always return the latest.

SPARQL XML Results 2006-01-25 (default format when `counter` is 0) name '`xml`' with URIs http://www.w3.org/TR/2006/WD-rdf-sparql-XMLres-20060125/ or http://www.w3.org/2005/sparql-results#

JSON name '`json`' and URI http://www.w3.org/2001/sw/DataAccess/json-sparql/

Older formats:

Name '`xml-v2`' with URIs http://www.w3.org/TR/2005/WD-rdf-sparql-XMLres-20050527/ or http://www.w3.org/2001/sw/DataAccess/rf1/result2

Name '`xml-v1`' with URIs http://www.w3.org/TR/2004/WD-rdf-sparql-XMLres-20041221/ or http://www.w3.org/2001/sw/DataAccess/rf1/result

If the writing succeeds, the query results will be exhausted.

`counter` : | index into the list of query result syntaxes
`name` : | pointer to store the name of the query result syntax (or NULL)
`label` : | pointer to store query result syntax readable label (or NULL)
`uri_string` : | pointer to store query result syntax URI string (or NULL)
Returns : | non 0 on failure of if counter is out of range

### rasqal_query_results_formatter

    rasqal_graph_query_results_formatter* query_results_formatter;

Rasqal query results formatter class.

### rasqal_new_query_results_formatter ()

    rasqal_query_results_formatter* rasqal_new_query_results_formatter
                                                (const char *name,
                                                 raptor_uri *uri);

Constructor - create a new rasqal_query_results_formatter object.

A query results format can be named or identified by a URI, both of which are optional. The default query results format will be used if both are NULL. `rasqal_query_results_formats_enumerate()` returns information on the known query results names, labels and URIs.

`name` : | the query results format name (or NULL)
`uri` : | raptor_uri query results format uri (or NULL)
Returns : | a new rasqal_query_results_formatter object or NULL on failure

### rasqal_free_query_results_formatter ()

    void        rasqal_free_query_results_formatter
                                                (rasqal_query_results_formatter *formatter);

Destructor - destroy a rasqal_query_results_formatter object.

`formatter` : | rasqal_query_results_formatter object

### rasqal_query_results_formatter_write ()

    int         rasqal_query_results_formatter_write
                                                (raptor_iostream *iostr,
                                                 rasqal_query_results_formatter *formatter,
                                                 rasqal_query_results *results,
                                                 raptor_uri *base_uri);

Write the query results using the given formatter to an iostream

See `rasqal_query_results_formats_enumerate()` to get the list of syntax URIs and their description.

`iostr` : | raptor_iostream to write the query to
`formatter` : | rasqal_query_results_formatter object
`results` : | rasqal_query_results query results format
`base_uri` : | raptor_uri base URI of the output format
Returns : | non-0 on failure