SPARQL Query Results XML Format (original) (raw)
Abstract
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 theSPARQL query language for RDF, developed by theW3C RDF Data Access Working Group (DAWG), part of theSemantic Web Activity as described in the activity statement .
Status of This Document
This is a live document and is subject to change without notice. It reflects the best effort of the editor to reflect implementation experience and incorporate input from various members of the WG, but is not yet endorsed by the WG as a whole.
The Changes appendix shows the differences between this document and the previous version.
Since the 1 August 2005 last call draft, we have been tracking threads in the public-rdf-dawg-comments archive more closely. A status report is updated every week or so. There seem to be no outstanding comments on this spec at the time of this writing.
Table of Contents
- 1. Introduction
- 2. Definition
- 2.1. Document Element
- 2.2. Header
- 2.3. Results
- 3. Examples
- 4. XML Schemas
- 5. Internet Media Type, File Extension and Macintosh File Type
- 6. References
- A Changes
1. Introduction
TheSPARQL Query Language for RDF [SPARQL-QUERY]defines several Query Result Forms(SPARQL Query section 10). This document defines a SPARQL Results Documentthat 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) inXML [XML].
2. Definition
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 inSection 4.
2.1. Document Element
The SPARQL Results Documentbegins with sparql
document element in thehttp://www.w3.org/2005/sparql-results#
namespace, written as follows:
Inside the sparql
element are two sub-elements,head
and a results element (either results
or boolean
) which must appear in that order.
2.2. Header
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 ofQuery Variablenames 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 elementsvariable
with the variable name as the value of an attribute name
giving a document like this:
For a boolean query result, no elements are required insidehead
and variable
must not be present.
For any query result, head
may also containlink
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.
2.3. Results
The second child-element of sparql
must appear after head
and is eitherresults
or boolean
. It is written even if the query results are empty.
2.3.1. Variable Binding Results
The results
element contains the complete sequence of query results.
NOTE: in previous versions of this document the results
element had two required attributes, distinct
andordered
. Both attributes have been removed (see change log entry for 2007-05-03).
For eachQuery Solutionin the query results, a result
child-element of results
is added giving a document like:
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 elementbinding
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:
<result>
<binding name="x"> ... </binding>
<binding name="hpage"> ... </binding>
</result>
...
The value of a query variable binding, which is an RDF Term, is included as the content of the binding
as follows:
RDF URI Reference U
<binding><uri>
U</uri></binding>
RDF Literal S
<binding><literal>
S</literal></binding>
RDF Literal S with language L
<binding><literal xml:lang="
L">
S</literal></binding>
RDF Typed Literal S with datatype URI D
<binding><literal datatype="
D">
S</literal></binding>
Blank Node label I
<binding><bnode>
I</bnode></binding>
If, for a particular solution, a variable is unbound, nobinding
element for that variable is included in theresult
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:
<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>
...
2.3.2. Boolean Results
A boolean result is written as the element content of aboolean
child-element of the sparql
element directly after a head
, containing either true
or false
as follows:
true
3. Examples
3.1. Variable Binding Results Examples
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>
3.2. Boolean Results Examples
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>
4. XML Schemas
There are normative XML schemas provided in the following formats:
- RELAX NG[RELAXNG] Compact[RELAXNG-COMPACT] in result.rnc
- RELAX NG XML in result.rng
- W3C XML Schema[XMLSCHEMA-1] in result.xsd
Note: this schema is machine-generated from the RELAX NG XML schema.
If W3C XML Schema is used, an xsi:schemaLocation
attribute can be used pointing to the schema as follows:
...
5. Internet Media Type, File Extension and Macintosh File Type
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 has been submitted to the IESG for review, approval, and registration with IANA. @@The IESG has not responded as of the publication date of this document@@.
Internet Media Type Registration Form
To: ietf-types@iana.org
Subject: Registration of media type application/sparql-results+xml
Type name:
application
Subtype name:
sparql-results+xml
Required parameters:
None
Optional parameters:
"charset": This parameter has identical semantics to the charset parameter of the "application/xml" media type as specified in [RFC3023], section 3.2.
Encoding considerations:
Identical to those of "application/xml" as specified in [RFC3023], section 3.2.
Security considerations:
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.
Interoperability considerations:
There are no known interoperability issues.
Published specification:
This specification.
Applications which use this media type:
No known applications currently use this media type.
Additional information:
Magic number(s):
As specified for "application/xml" in [RFC3023], section 3.2.
File extension(s):
".srx"
Fragment identifiers:
Identical to that of "application/xml" as described in RFC 3023[RFC3023], section 5.
Base URI:
As specified in [RFC3023], section 6.
Macintosh file type code(s):
"TEXT"
Person & email address to contact for further information:
Dave Beckett, Eric Prud'hommeaux public-rdf-dawg-comments@w3.org
Intended usage:
COMMON
Restrictions on usage:
None
Author/Change controller:
The SPARQL specification is a work product of the World Wide Web Consortium's RDF Data Access Working Group. The W3C has change control over these specifications.
References
[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.
6. References
[XML]
Extensible Markup Language (XML) 1.0, Third Edition, T. Bray, J. Paoli, C.M. Sperberg-McQueen, E. Maler, F. Yergeau, Editors, W3C Recommendation, 4 February 2004. This document is http://www.w3.org/TR/2004/REC-xml-20040204 . The latest version is available at http://www.w3.org/TR/REC-xml .
[SPARQL-QUERY]
SPARQL Query Language for RDF, E. Prud'hommeaux, A. Seaborne, Editors, W3C Working Draft (work in progress), 21 July 2005. This document is http://www.w3.org/TR/2005/WD-rdf-sparql-query-20050721/ . The latest version is available at http://www.w3.org/TR/rdf-sparql-query/ .
[RELAXNG]
RELAX NG Specification, James Clark and MURATA Makoto, Editors, OASIS Committee Specification, 3 December 2001. This document is http://www.oasis-open.org/committees/relax-ng/spec-20011203.html . The latest version is available at http://www.oasis-open.org/committees/relax-ng/spec.html .
[RELAXNG-COMPACT]
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 .
[XMLSCHEMA-1]
XML Schema Part 1: Structures Second Edition, D. Beech, N. Mendelsohn, M. Maloney, H. S. Thompson, Editors, W3C Recommendation, 28 October 2004. This document is http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/ . The latest version is available at http://www.w3.org/TR/xmlschema-1/ .
A. Changes (Informative)
2007-05-03. The attributes 'ordered' and 'distinct' of the 'results' element have been removed per WG decision at 2007-05-01 telcon.
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 asSPARQL Query Results XML Format, W3C Working Draft 1 August 2005.
For earlier changes see thechanges in the 1 August 2005 working draft.