图表的RDF / XML

时间:2016-05-24 12:55:45

标签: xml rdf rdf-xml

我为图形编写了以下XML:

 `Person ------> Organization`
 `Person ------> name`

和组织进一步拥有节点

 `Organization----->Title`
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:foaf="http://www.example.org/terms/">

  <rdf:Description rdf:about="person">
  <foaf:name>Usman</foaf:name>
  </rdf:Description>

但我不知道在哪里添加organization节点及其进一步的子节点作为标题?

1 个答案:

答案 0 :(得分:2)

手工编写RDF / XML非常容易出错,我最强烈的建议是以不同的格式编写,然后将其转换为RDF / XML。 RDF / XML并非设计为人类可读的,并且RDF / XML可以通过多种方式表示相同的RDF图形。

我首先编写以下Turtle文档(作为示例):

@prefix : <http://example.org/>

:john a :Person .
:john :hasName "John" .
:john :belongsTo :company42 .

:company42 a :Company .
:company42 :hasName "The Company" .

然后,如果你需要RDF / XML,你可以使用几乎所有的RDF库来转换它,以获得:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://example.org/">
  <Person rdf:about="http://example.org/john">
    <hasName>John</hasName>
    <belongsTo>
      <Company rdf:about="http://example.org/company42">
        <hasName>The Company</hasName>
      </Company>
    </belongsTo>
  </Person>
</rdf:RDF>

要突出显示RDF / XML可能性的变化,这里是相同的RDF图,仍然是RDF / XML:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://example.org/" > 
  <rdf:Description rdf:about="http://example.org/john">
    <rdf:type rdf:resource="http://example.org/Person"/>
    <hasName>John</hasName>
    <belongsTo rdf:resource="http://example.org/company42"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/company42">
    <rdf:type rdf:resource="http://example.org/Company"/>
    <hasName>The Company</hasName>
  </rdf:Description>
</rdf:RDF>

使用人类可读的和人类可写的表单(如Turtle)要容易得多。随着您对Turtle的熟练程度越来越高,您可以使用它允许的方便的缩写。例如,上面的图也可以这样写,这节省了一些输入:

@prefix : <http://example.org/>

:john a :Person ;
      :hasName "John" ;
      :belongsTo :company42 .

:company42 a :Company ;
           :hasName "The Company" .
相关问题