1

I wrote the following XML for graph something like:

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

and organization further has on node

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

But I don't know where to add the organization node with its further child node as title?

unor
  • 92,415
  • 26
  • 211
  • 360
Chili Mili
  • 79
  • 1
  • 6

1 Answers1

2

Writing RDF/XML by hand is very error-prone, and my strongest recommendation is to write in a different format and then convert it to RDF/XML. RDF/XML is not designed to be human-readable, and the same RDF graph can be represented in RDF/XML in many different ways.

I'd start by writing the following Turtle document (as an example):

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

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

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

Then, if you need RDF/XML, you can convert it using just about any RDF library out there, to get:

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

To highlight the variation in RDF/XML possibilities, here's the same RDF graph, still in 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>

It's much easier to use the human-readable and human-writable forms, like Turtle. As you become more experienced with Turtle, you can use the convenient shorthands that it allows. For instance, the graph above can also be written like this, which saves some typing:

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

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

:company42 a :Company ;
           :hasName "The Company" .
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353