Copyright ©2005, 2006 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
RDF is a flexible, extensible way to represent information about World Wide Web resources. It is used to represent, among other things, personal information, social networks, metadata about digital artifacts like music and images, as well as provide a means of integration over disparate sources of information. A standardized query language for RDF data with multiple implementations offers developers and end users a way to write and to consume the results of queries across this wide range of information.
This document describes an XML format for the variable binding and boolean results formats provided by the SPARQL query language for RDF, developed by the W3C RDF Data Access Working Group (DAWG), part of the Semantic Web Activity as described in the activity statement .
This is a Last Call Working Draft of the SPARQL Query Results XML Format. It is a deliverable of the RDF Data Access Working Group (DAWG), part of the W3C Semantic Web Activity.
The change log appendix shows the one design change since the 1 August 2005 draft.
Comments are due 10 February 2006 to public-rdf-dawg-comments@w3.org, a mailing list with a public archive.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced under the 5 February 2004 W3C Patent Policy. The Working Group maintains a public list of patent disclosures relevant to this document; that page also includes instructions for disclosing [and excluding] a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) with respect to this specification should disclose the information in accordance with section 6 of the W3C Patent Policy.
Per section 4 of the W3C Patent Policy, Working Group participants have 150 days from the title page date of this document to exclude essential claims from the W3C RF licensing requirements with respect to this document series. Exclusions are with respect to the exclusion reference document, defined by the W3C Patent Policy to be the latest version of a document in this series that is published no later than 90 days after the title page date of this document.
The
SPARQL Query Language for RDF
[SPARQL-QUERY]
defines several Query Result Forms
(SPARQL Query section 10).
This document defines a SPARQL Results Document
that encodes
the variable binding query results from SELECT
queries
(SPARQL Query section 10.2)
and boolean query results from ASK
queries
(SPARQL Query section 10.5)
in
XML
[XML].
Definition: SPARQL Results Document
A SPARQL Results Document is an XML document that is valid with respect to either the RELAX NG XML Schema or the W3C XML Schema in Section 4.
The SPARQL Results Document
begins with sparql
document element in the
http://www.w3.org/2005/sparql-results#
namespace,
written as follows:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... </sparql>
Inside the sparql
element are two sub-elements,
head
and
a results element (either results
or boolean
)
which must appear in that order.
The head
element is the first child element of
the sparql
element.
For a variable binding query result, head
must contain a
sequence of elements describing the set of
Query Variable
names in the
Solution Sequence
(here called query results).
The order of the variable names in the sequence is the order of
the variable names given to the argument of the SELECT
statement in the SPARQL query. If SELECT *
is used, the
order of the names is undefined.
Inside the head
element, the ordered sequence of
variable names chosen are used to create empty child elements
variable
with the variable name as the value of an
attribute name
giving a document like this:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> <variable name="hpage"/> <variable name="name"/> <variable name="mbox"/> <variable name="blurb"/> </head> ... </sparql>
For a boolean query result, no elements are required inside
head
and variable
must not be present.
For any query result, head
may also contain
link
child elements with an href
attribute
containing a relative URI that provides a link to some additional
metadata about the query results. The relative URI is resolved
against the in-scope base URI which is usually the query results
format document URI. link
elements must appear after
any variable
elements that are present.
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> ... <link href="metadata.rdf"/> </head> ... </sparql>
The second child-element of sparql
must appear after head
and is either
results
or boolean
.
It is written even if the query results are empty.
The results
element has 2 required attributes which
both take boolean values: either true
or false
.
ordered
attribute indicates whether or not
the results have an ordering, such as given by a SPARQL query containing
ORDER BY
. If the attribute value is true
then the XML element order of result
elements must match
the query results order.
distinct
attribute indicates that the results
are distinct (contain no duplicates), such as given by a SPARQL
query using SELECT DISTINCT
.
For each
Query Solution
in the query results, a result
child-element of results
is added giving
a document like:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... head ... <results ordered="false" distinct="false"> <result>... </result> <result>... </result> ... </results> </sparql>
Each result
element corresponds to one Query
Solution in a result and contains child elements (in no particular order) for each Query
Variable that appears in the solution. It
is used to record how the query variables bind to RDF
Terms.
Each binding inside a solution is written as an element
binding
as a child of result
with the query
variable name as the value of the name
attribute. So for a
result binding two variables x and hpage it would
look like:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> <variable name="hpage"/> </head> <results ordered="false" distinct="false"> <result> <binding name="x"> ... </binding> <binding name="hpage"> ... </binding> </result> <result> <binding name="x"> ... </binding> <binding name="hpage"> ... </binding> </result> ... </results> </sparql>
The value of a query variable binding, which is an RDF Term, is
included as the content of the binding
as follows:
<binding><uri>
U</uri></binding>
<binding><literal>
S</literal></binding>
<binding><literal
xml:lang="
L">
S</literal></binding>
<binding><literal
datatype="
D">
S</literal></binding>
<binding><bnode>
I</bnode></binding>
If, for a particular solution, a variable is unbound, no
binding
element for that variable is included in the
result
element.
Note: The blank node label I is scoped to the result set XML document and need not have any association to the blank node label for that RDF Term in the query graph.
An example of a query solution encoded in this format is as follows:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="x"/> <variable name="hpage"/> <variable name="name"/> <variable name="age"/> <variable name="mbox"/> <variable name="friend"/> </head> <results ordered="true" distinct="false"> <result> <binding name="x"> <bnode>r2</bnode> </binding> <binding name="hpage"> <uri>http://work.example.org/bob/</uri> </binding> <binding name="name"> <literal xml:lang="en">Bob</literal> </binding> <binding name="age"> <literal datatype="http://www.w3.org/2001/XMLSchema#integer">30</literal> </binding> <binding name="mbox"> <uri>mailto:bob@work.example.org</uri> </binding> </result> ... </results> </sparql>
A boolean result is written as the element content of a
boolean
child-element of the sparql
element directly after a head
,
containing either true
or false
as follows:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#"> ... head ... <boolean>true</boolean> </sparql>
An example SELECT
SPARQL Query in
example.rq operating
on query graph Turtle/N3 data in data.n3
providing ordered variable binding query results written in XML
in output.srx.
This XML can be transformed into XHTML using the sample XML Query script result2-to-html.xq giving output-xquery.html or with XSLT sheet result2-to-html.xsl giving output-xslt.html
An example ASK
SPARQL Query in
example2.rq operating
on query graph Turtle/N3 data in data.n3
provides a boolean query result written in XML
in output2.srx.
This XML can be transformed into XHTML using the sample XML Query script result2-to-html.xq giving output-xquery2.html or with XSLT sheet result2-to-html.xsl giving output-xslt2.html
There are normative XML schemas provided in the following formats:
If W3C XML Schema is used, an xsi:schemaLocation
attribute can be used pointing to the schema as follows:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/TR/2005/WD-rdf-sparql-XMLres-20050801/result2.xsd"> ... </sparql>
The Internet Media Type / MIME Type for the SPARQL Query Results XML Format is "application/sparql-results+xml".
It is recommended that result files have the extension ".srx" (all lowercase) on all platforms.
It is recommended that result files stored on Macintosh HFS file systems be given a file type of "TEXT".
This information that follows is intended to be submitted to the IESG for review, approval, and registration with IANA.
To: ietf-types@iana.org
Subject: Registration of media type application/sparql-results+xml
SPARQL query results uses URIs. See Section 7 of [RFC3986].
SPARQL query results uses IRIs. See Section 8 of [RFC3987].
As this media type uses the "+xml" convention, it shares the same security considerations as described in [RFC3023], section 10.
[RFC3023] Murata, M., St. Laurent, S., and D. Kohn, "XML Media Types", RFC 3023, January 2001.
[RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, January 2005.
[RFC3987] Duerst, M. and M. Suignard, "Internationalized Resource Identifiers (IRIs)", RFC 3987, January 2005.
2005-12-21. Unbound variables are no longer explicitly encoded, instead binding element for such variables is left out. Restriction on order of binding elements inside a solution is dropped. Cf. WG decision at 2005-12-20 telcon.
2005-08-02. Fixed typo, reverted to editor's draft format.
2005-08-01. Published as SPARQL Query Results XML Format, W3C Working Draft 1 August 2005.
For earlier changes see the changes in the 1 August 2005 working draft.