Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting resultset to RDF/XML in Jena

Tags:

java

xml

rdf

jena

I'm trying to convert a 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 the code is to verify the correct behaviour of the query (it works!), but I get in the console the following output:

<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>

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

like image 605
rok Avatar asked Nov 26 '25 05:11

rok


1 Answers

The problem is that your print debugging actually consumes all the results, leaving the ResultSet at the end. There are no more results available when you try to output it as RDF/XML.

You can fix it by making the 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);
like image 200
user205512 Avatar answered Nov 28 '25 21:11

user205512



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!