You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Elli Schwarz <el...@yahoo.com> on 2013/01/16 23:02:06 UTC
Using a single quote in a SPARQL query
Hello,
I'm parsing a string into a SPARQL query using the following syntax:
Query query = QueryFactory
.create("SELECT * where {?foo ?bar 'FOO'}");
String queryString = query.serialize();
System.out.println(queryString);
and when the queryString is printed out, the single quote is replaced with a double quote. The problem is, if I want to put a double quote in the text of the string, ' "FOO" ' it won't work since the Query object interprets this as " "Foo" ".
And if I try this to escape the double quotes for Java:
Query query = QueryFactory
.create("SELECT * where {?foo ?bar ' \"FOO\" '}");
It works, but the output I get when printing out the query string is SELECT * WHERE { ?foo ?bar " \"FOO\" " } which is not what I expect!
The same query works in Fuseki directly:
SELECT * where {?foo ?bar ' "FOO" '}
This is what I'm trying to be able to do from Java.
Thanks for your help,
Elli
Re: Using a single quote in a SPARQL query
Posted by Andy Seaborne <an...@apache.org>.
On 16/01/13 22:02, Elli Schwarz wrote:
> Hello,
>
> I'm parsing a string into a SPARQL query using the following syntax:
> Query query = QueryFactory
> .create("SELECT * where {?foo ?bar 'FOO'}");
> String queryString = query.serialize();
> System.out.println(queryString);
>
> and when the queryString is printed out, the single quote is
> replaced
with a double quote. The problem is, if I want to put a double quote in
the text of the string, ' "FOO" ' it won't work since the Query object
interprets this as " "Foo" ".
\"
>
> And if I try this to escape the double quotes for Java:
> Query query = QueryFactory
> .create("SELECT * where {?foo ?bar ' \"FOO\" '}");
No - you need to cope with Java quoting as well.
"SELECT * where {?foo ?bar ' \\\"FOO\\\" '}"
Yes = 3 \
\\ puts \ into to the string
\" puts " into the string
so overall you have \" in the SPARQL string.
> It works, but the output I get when printing out the query string is SELECT * WHERE { ?foo ?bar " \"FOO\" " } which is not what I expect!
but it's OK.
The outer string syntax does not matter
'"FOO"' = "\"FOO\""
>
> The same query works in Fuseki directly:
>
> SELECT * where {?foo ?bar ' "FOO" '}
>
>
> This is what I'm trying to be able to do from Java.
>
> Thanks for your help,
> Elli
>