简体   繁体   English

在 Jena 中将结果集转换为 RDF/XML

[英]converting resultset to RDF/XML in Jena

I'm trying to convert a resultset in XML/RDF format but with this code:我正在尝试以 XML/RDF 格式转换resultset ,但使用以下代码:

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?不包含我的数据,我的代码有什么问题?

The problem is that your print debugging actually consumes all the results, leaving the ResultSet at the end.问题是您的打印调试实际上消耗了所有结果,最后留下了ResultSet There are no more results available when you try to output it as RDF/XML.当您尝试将其输出为 RDF/XML 时,没有更多可用的结果。

You can fix it by making the ResultSet rewindable :您可以通过使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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM