SPARQL Result Format

Created on Feb. 23, 2013, 11:43 a.m. by Hevok & updated by Hevok on May 2, 2013, 5:20 p.m.

With SPARQL (Protocol and RDF Query Language) one can define Query Patterns against and RDF Knowledge Base and the RDF Graph within the knowledge base will be traversed with the help of Graph Patterns.

SPARQL is not only a Query Language

SPARQL besides the Query Language is also a Protocol Layer where the communication SPARQL Endpoint is arranged and defined. On the other hand SPARQL also defines an Output Format of the answer of the Query against a SPARQL Endpoint.

In responds to SPARQL Query the results from the SPARQL Endpoint will be in the form of valid XML Documents, for example. As the type of the XML document sparql xml namespace must be defined. In the rest of the document the results of the Query will be explained.

As each XML document consists of a head and body. In the header of the SPARQL result XML file there are the names of all variables that have been used in the Query and will be fulfilled. The name of all these Variables also give the name of the columns of the result Table.

There results itself will be within the results Markup keywords. In the results one will have single sections for each single result where one has bindings that means a Variable that has already been cited in the header will be bound to some value.

Within the results section there are some bindings, like a binding of a Variable named x to a Blank Node that has a specific name, or a binding to variable with the name hpage to a URI that also gives this URI. Then there can be a binding to a Literal to a Variable called name in which a Literal. In a Literal on can also define the Language Tag. One can also define a a type literal binding for instance to variable age and one has there a literal that has specific datatype like Integer which comes from the XML Schema namespace. Further one can bind a Variable to name of mail box and there on has the Email address given as a URI. Overall there are for different kinds of Variables one has different types of Markup Languages within the result XML file. For each Variable and each result row one will have one result with a binding to a Variable. So for each line one has a result paragraph within the XML Document and within each XML result Paragraph one has the binding for each Variable.

  • SPARQL results are given as well formed and valid XML documents

    <?xml version="1.0"?>
    <sparql xmlns="">]
  • In a element all Variables of the SPARQL Query are listed

        <variable name="x"/>
        <variable name="hpage"/>
        <variable name="name"/>
        <variable name="mbox"/>
        <variable name="blurb"/>
  • For each SPARQL Query result exists a element

        <?xml version="1.0"?>
        <sparql xmlns="">]
                <variable name="x" />
                <binding name="x"> ... </binding>
                <binding name="hpage"> .. </binding>
            <results> ... </results>
  • Within a element a Variable is bound to a result

            <binding name="x">
            <binding name="hpage">
            <binding name="name">
                <literal xml:lang="en">Hevok</literal>
            <binding name="age">
                <literal datatype="">]
            <binding name="mbox">

This is the way the result is returned from the SPARQL Endpoint which can easily be interpreted.

It is also very simple for a Program to access a SPARQL Endpoint to receive the result as an XML File, then to parse it and interpret it as a Table.


Tags: coding, programming, output, formatting
Categories: Tutorial
Parent: SPARQL

Update entry (Admin) | See changes

Comment on This Data Unit