Invalid XML in ResultSet

RDF literals may contain characters that are not allowed in XML, in particular XML1.0 [Extensible Markup Language (XML) 1.0 (Fifth Edition)]. When these literals are returned in a SPARQL Result Set, the returned XML is rendered invalid and can not be correctly parsed by an XML parser as used e.g. in Jena.

Example triple:

<urn:s> <urn:p> "BEL character is \u0007" .

Sparql Query:

SELECT ?o WHERE { <urn:s> <urn:p> ?o . }

Result Set:

<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'><head><variable name='o'/></head>
<results><result><binding name='o'><literal>BEL character is a</literal></binding></result></results>
</sparql>

In the Result Set the character <0x07> is contained (represented here as an "a") which is not allowed. The character should be escaped, e.g. "/u0007" or XML1.1 should be declared in the xml header.