SPARQL Result Format

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="http://www.w3.org/2005/sparql-results#">]
        ...
    </sparql>
    
  • In a element all Variables of the SPARQL Query are listed

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

        <?xml version="1.0"?>
        <sparql xmlns="http://www.w3.org/2005/sparql-results#">]
            <head>
                <variable name="x" />
                ...
            </head>
            <results>
                <result
                <binding name="x"> ... </binding>
                <binding name="hpage"> .. </binding>
            </results>
    
            <results> ... </results>
            </results>
        </sparql>
    
  • Within a element a Variable is bound to a result

        <result>
            <binding name="x">
                <bnode>r2</bnode>
            </binding>
            <binding name="hpage">
                <uri>http://work.example.org/<]/uri>
            </binding>
            <binding name="name">
                <literal xml:lang="en">Hevok</literal>
            </binding>
            <binding name="age">
                <literal datatype="http://www.w3.org/2001/XMLSchema#integer">]
                    30
                </literal>
            </binding>
            <binding name="mbox">
                <uri>mailto:hevok@work.denigma.org</uri>
            </binding>
        </result>
    

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.

sparkler.jpg/
Edit tutorial

Comment on This Data Unit