Copyright ©2004 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 results format 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 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/.
This is a first Public Working Draft of the SPARQL Variable Binding Results XML Format produced by the RDF Data Access Working Group, (part of the Semantic Web Activity) for review by W3C Members and other interested parties. It reflects the best effort of the editors to reflect implementation experience and incorporate input from various members of the WG, but is not yet endorsed by the WG as a whole. Please send comments to the public public-rdf-dawg-comments@w3.org, a mailing list with a public archive. The query result format defined by this document is intended to make RDF query results conveniently available to XML applications. The working group would appreciate feedback and suggestions from developers of XPath and SAX applications.
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.
This document defines a format for encoding variable binding results made by the SPARQL Query Language for RDF [SPARQL-QUERY] in XML [XML].
SPARQL Query defines several query result forms (SPARQL Query section 10) and this document defines an XML serialisation for the SELECT form of results, a Query Results (SPARQL Query section 2.5).
The XML format has document element sparql
element in the
http://www.w3.org/2001/sw/DataAccess/rf1/result
namespace,
written as follows:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"> ... </sparql>
Inside the sparql
element are two sub-elements,
head
and results
which must appear in
that order.
The head
element is the first child element
of sparql
and contains a sequence of
elements describing the set of Query Variable
(SPARQL Query section 2.2)
names in the Query Results. The order chosen to serialize
the set of variable names into a sequence of elements is not
significant, but the order used inside head
must be
the same as that used in the result
elements, described
below.
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/2001/sw/DataAccess/rf1/result"> <head> <variable name="x"/> <variable name="hpage"/> <variable name="name"/> <variable name="mbox"/> <variable name="blurb"/> </head> ... </sparql>
The results
element is the second child-element of
sparql
and must appear after head
.
It is written even if the Query Results is empty.
For each Query Solution
(SPARQL Query section 2.5)
in the Query Results, a result
child-element of results
is added giving
a document something like:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"> ... head ... <results> <result> </result> <result> </result> ... </results> </sparql>
Each result
element corresponds to one Query
Solution in the result set, and contains child elements for each
Query Variable that appears in the solution (ordered the
same as the variable
child elements of
head
) and recording the RDF Term
(SPARQL Query section 2.2)
value of the Query Variable.
The RDF Term encoding in XML for a variable named var in the solution is as follows:
<
var bound="false"/>
<
var uri="
U"/>
<
var>
S</
var>
<
var xml:lang="
L">
S</
var>
<
var datatype="
D">
S</
var>
<
var bnodeid="
I"/>
Note: The blank node label I is scoped to the result set XML document and does not have any association to the the blank node label for that RDF Term in the query graph.
A query solution encoded in this format could look something like the following:
<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2001/sw/DataAccess/rf1/result"> ... head ... <results> <result> <x bnodeid="r2"/> <hpage uri="http://work.example.org/bob/"/> <name xml:lang="en">Bob</name> <mbox uri="mailto:bob@work"/> <age datatype="http://www.w3.org/2001/XMLSchema#integer">30</age> <blurb bound="false"/> <friend bnodeid="r1"/> </result> ... </results> </sparql>
An example SPARQL Query in example.rq operating on query graph Turtle/N3 data in data.n3 provides query results in XML output.xml. following the definition in section 2
This XML can be transformed into XHTML using the sample XML Query script result-to-html.xq giving output-xquery.html or with XSLT sheet result-to-html.xsl giving output-xslt.html
There are XML schemas for this format in the following formats:
These schemas are for information only.
ISSUE: Normativeness of the XML schemas. Pick one?
2004-12-20 variables
element renamed to head
Replaced variables
child elements <foo/>
with <variable name="foo"/>
Made unbound variables appear as <var bound="false"/>
2004-12-15 Document element now <sparql>
Attribute id
now bnodeid
Unbound query variables are omitted from a solution.
Noted that bnodeid values are scoped to the XML result document.
2004-12-13 Added definitions section
Switched href to uri as
agreed 2004-09-29
2004-12-08 Initial version. Based on Updated DAWG variable binding results XML format, 2004-11-26 and draft XML query results format spec, 2004-09.28