Converting Results to RDF / XML in Jena

I'm trying to convert resultset

in XML / RDF format, but with this code:

ResultSet result = rmParliament.selectQuery(select);
System.out.println(ResultSetFormatter.asText(result));
ResultSetFormatter.outputAsRDF(System.out, "RDF/XML", result);

      

The second line of code is to check if the request behavior is correct (it works!), But I get the following output in the console:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rs="http://www.w3.org/2001/sw/DataAccess/tests/result-set#" > 
 <rdf:Description rdf:nodeID="A0">
    <rs:size rdf:datatype="http://www.w3.org/2001/XMLSchema#int">0</rs:size>
    <rs:resultVariable>value</rs:resultVariable>
    <rs:resultVariable>property</rs:resultVariable>
    <rs:resultVariable>name</rs:resultVariable>
    <rdf:type rdf:resource="http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet"/>
 </rdf:Description>
</rdf:RDF>

      

Doesn't contain my data, what's wrong with my code?

+3


source to share


1 answer


The problem is that your debugging is actually consuming all the results, leaving it ResultSet

at the end. There are no more results when trying to output it as RDF / XML.

You can fix this by making a ResultSet

rewindable :



ResultSetRewindable result =
    ResultSetFactory.makeRewindable( rmParliament.selectQuery(select) );
System.out.println(ResultSetFormatter.asText(result));
result.reset(); // back to the start
ResultSetFormatter.outputAsRDF(System.out, "RDF/XML", result);

      

+3


source







All Articles