SPARQL Variable Binding Results XML Format

W3C Working Draft 21 December 2004

This version:
Latest version:
Dave Beckett, ILRT University of Bristol


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 .

Status of this Document

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.

Table of Contents

1 Introduction

This document defines a format for encoding variable binding results made by the SPARQL Query Language for RDF [SPARQL-QUERY] in XML [XML].

2. Definition

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).

2.1. Document Element

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">

Inside the sparql element are two sub-elements, head and results which must appear in that order.

2.2. Header

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">

    <variable name="x"/>
    <variable name="hpage"/>
    <variable name="name"/>
    <variable name="mbox"/>
    <variable name="blurb"/>

2.3. Query Results

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 ...



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:

No binding
<var bound="false"/>
RDF URI Reference U
<var uri="U"/>
RDF Literal S
RDF Literal S with language L
<var xml:lang="L">S</var>
RDF Literal S with datatype URI D
<var datatype="D">S</var>
Blank Node label I
<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 ...


      <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"/>



3. Examples

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

4. XML Schemas

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?

5. References

Extensible Markup Language (XML) 1.0, Third Edition, T. Bray, J. Paoli, C.M. Sperberg-McQueen, E. Maler, F. yergeau, Editors. World Wide Web Consortium. 4 February 2004. This version is http://www.w3.org/TR/2004/REC-xml-20040204. The latest version of XML is available at http://www.w3.org/TR/REC-xml.
SPARQL Query Language for RDF, E. Prud'hommeaux, A. Seaborne, Editors. World Wide Web Consortium. 12 October 2004. Work in progress. This version is http://www.w3.org/TR/2004/WD-rdf-sparql-query-20041012/. The latest version of SPARQL Query Language for RDF is available at http://www.w3.org/TR/rdf-sparql-query/.
RELAX NG Specification, James Clark and MURATA Makoto, Editors, OASIS Committee Specification, 3 December 2001. This version of RELAX NG is http://www.oasis-open.org/committees/relax-ng/spec-20011203.html. The latest version of the RELAX NG Specification is at http://www.oasis-open.org/committees/relax-ng/spec.html.
RELAX NG Compact Syntax, James Clark, Editor. OASIS Committee Specification, 21 November 2002. This document is http://www.oasis-open.org/committees/relax-ng/compact-20021121.html.

A. Changes

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