converting resultset to RDF/XML in Jena

时光怂恿深爱的人放手 提交于 2019-12-01 22:57:32

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/27168750/converting-resultset-to-rdf-xml-in-jena

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!