Friday, July 3, 2015

A simple XML syntax for RDF


Dave Winer just tweeted a link to a Tim Bray blog post about RDF: https://twitter.com/davewiner/status/617027803737944064. I think one RDF's biggest problems is that it is too damn verbose.

Here's my idea for a simple, terse syntax.  In XML.  It's derived from Tim's RPV thoughts.
  <resource target='...uri this triplet is about...'
           propertyuribase='base URI for properties, optional'>
    <value property='uri of the property'>
      text or a nested <resource> element
    </value>
    ... multiple value elements ...
  </resource>

I think properties will often be grouped in "clumps" from the same general URI space.  So I defined a "property base" attribute; any relative property URI's are taken to be relative to the nearest containing base.

Using the example from Tim's post, I get
  <resource target='http://www.w3.org/TR/rdf-syntax-grammar'
            propertyuribase='http://www.example.com/terms/'>
    <value prop='fullName'>Dave Backett</value>
    <value prop='homePage'>http://purl.org/net/dajobe/</value>
  </resource>
  <resource target='http://purl.org/net/dajobe/'>
    <value prop='http://purl.org/dc/elements/1.1/title'>
      RDF/XML Syntax Specification (Revised)
    </value>
  </resource>

That's still a bit verbose, so let's use Tim's really short names:

  <r t='http://www.w3.org/TR/rdf-syntax-grammar'
       pb='http://www.example.com/terms/'>
    <v p='fullName'>Dave Backett</v>
    <v p='homePage'>http://purl.org/net/dajobe/</v>
  </r>
  <r target='http://purl.org/net/dajobe/'>
    <v prop='http://purl.org/dc/elements/1.1/title'>
      RDF/XML Syntax Specification (Revised)
    </v>
  </r>

We need a container, and it might be nice to be able to change the URI prefix.  So we can say a nested 'r' element defaults to the 'pb' and 't' of it's nearest containing element. It's an error for a 'v' to appear without a 't' in-scope, just like it's an error for a relative 'p' attribute to appear without a 'base' in scope.

I've managed to foget most of knowledge about XML Schema languages, including XSD and Schematron, so I have no idea if the recursive "r" element stuff can be properly defined.  But I do know that this seems to translate trivially into JSON, which is what all the cool kids are using these days.

No comments:

Post a Comment