0

I wrote SPARQL in String queryString

 "SELECT DISTINCT ?dog ?p ?o " +
            "WHERE {" +
            "?dog <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://test#dog>. " +
            "?dog ?p ?o. " +
            "}";

...

   while (rs_s.hasNext()) {
        QuerySolution qs = rs_s.next();
        String s1 = qs.get("dog").toString();
        String s2 = qs.get("p").toString();
        String s3 = qs.get("o").toString();

As a result, I got a triple format. How do I get it with RDF XML?

user20297975
  • 129
  • 8
  • 1
    wrong query type, use a `CONSTRUCT` query, see [specs](https://www.w3.org/TR/sparql11-query/#construct) - and Jena will return a `Model` then which you can serialize as RDF/XML – UninformedUser Dec 01 '22 at 07:09
  • Are you saying that if I use CONSTRUCT query, I can make RDF XML with Model.write? – user20297975 Dec 01 '22 at 08:22
  • well, yes - the whole idea of `CONSTRUCT` queries is to return proper RDF data, and in Jena you'll get the result as a `Model` object which you can write to disk in "RDF/XML" syntax – UninformedUser Dec 01 '22 at 09:26
  • I'm sorry, but what does the word "wrong query type" mean? "CONSTRUCT DISTINCT ?dog ?p ?o " + "WHERE {" + "?dog . " + "?dog ?p ?o. " + "}"; Does this mean that RDF data comes out? What is output? – user20297975 Dec 02 '22 at 06:34
  • 1
    (1) Syntax, `CONSTRUCT {..} WHERE {..}` (2) call `QueryExecution.execConstruct` to get a Model. – AndyS Dec 02 '22 at 15:32
  • I can't call QueryExecution.execConstruct. Where is the library located? I did : import org.apache.jena.query.QueryExecution; So, I can use QueryExecution and result came out as a triple – user20297975 Dec 03 '22 at 05:52

0 Answers0