耶拿出口:嵌套元素或添加描述

时间:2018-11-27 11:58:55

标签: java jena

我想将jena数据库导出到文件中,当我使用RDF / XML时,我使用rdf:Description获取对象。当我使用RDF / XML-ABBREV时,我得到的对象带有正确的标签,但它们是嵌套的。

dataset = TDBFactory.createDataset("C:\\Users\\PC\\Desktop\\db\\");
Model model = dataset.getDefaultModel();

outputPath ="C:\\Users\\PC\\Desktop\\file.xml";
writer = new FileWriter(outputPath);
model.write(writer, "RDF/XML-ABBREV");

所以,谁能告诉我如何解决这个问题。

我尝试了this,但响应如下:

如果我使用:

RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PRETTY);

然后给前缀一个很好的前缀,但是对象是嵌套的:

<cim:VoltageLevel rdf:about="urn:uuid:0#_2ecd8d06-9088-4adc-8800-80d5e73c1b94">
 <cim:IdentifiedObject.name>Domžale 20kV</cim:IdentifiedObject.name>
 <cim:VoltageLevel.BaseVoltage>
  <cim:BaseVoltage rdf:about="urn:uuid:0#_5132f6db-1342-4f27-b701-2c446aba1590">
    <cim:IdentifiedObject.name>20kV</cim:IdentifiedObject.name>
    <cim:BaseVoltage.nominalVoltage>20000</cim:BaseVoltage.nominalVoltage>
  </cim:BaseVoltage>
</cim:VoltageLevel.BaseVoltage>
<cim:VoltageLevel.highVoltageLimit>22000</cim:VoltageLevel.highVoltageLimit>
<cim:VoltageLevel.lowVoltageLimit>18000</cim:VoltageLevel.lowVoltageLimit>
<cim:VoltageLevel.Substation>
  <cim:Substation rdf:about="urn:uuid:0#_dc3cd19e-3ea5-4f61-89db-656ee1b8684a">
    <cim:IdentifiedObject.name>RTP Domžale</cim:IdentifiedObject.name>
    <cim:Substation.Region rdf:resource="urn:uuid:0#_ee169401-9cef-417d-b01e-db2f9d3ce98b"/>
  </cim:Substation>
</cim:VoltageLevel.Substation>

如果我使用

model.write(System.out, "RDF/XML");

我得到的对象是我想要的,但我要的不是“描述”,而是要有正确的标签:

  <rdf:Description rdf:about="urn:uuid:0#_2ecd8d06-9088-4adc-8800-80d5e73c1b94">
<cim:IdentifiedObject.name>Domžale 20kV</cim:IdentifiedObject.name>
<rdf:type rdf:resource="http://iec.ch/TC57/2013/CIM-schema-cim16#VoltageLevel"/>
<cim:VoltageLevel.BaseVoltage rdf:resource="urn:uuid:0#_5132f6db-1342-4f27-b701-2c446aba1590"/>
<cim:VoltageLevel.highVoltageLimit>22000</cim:VoltageLevel.highVoltageLimit>
<cim:VoltageLevel.lowVoltageLimit>18000</cim:VoltageLevel.lowVoltageLimit>
 <cim:VoltageLevel.Substation rdf:resource="urn:uuid:0#_dc3cd19e-3ea5-4f61-89db-656ee1b8684a"/>
 </rdf:Description>

0 个答案:

没有答案