Portrait of Edd Dumbill, taken by Giles Turnbull

Subscribe to updates

Feed icon Atom or RSS

or get email updates

What I make

a conference management web application

XTech Conference
a European web technology conference

Processing FOAF with C#

Early today, uh, make that yesterday, I had an interesting decision to make. I was starting on developing FOAF code for Dashboard. FOAF is an RDF/XML vocabulary and thus, while it's possible to process it with an XML parser alone, it's a lot easier to use an RDF parser. Unfortunately, Mono doesn't come with an RDF parser. Knowing that, I considered using an XSLT stylesheet to transform the common formulations of FOAF files into XML which I could interrogate with XPath.

However, going down that route would be flawed for the following reasons.

  • It's fragile. Any syntax-based processing would have to evolve into an RDF parser before it could be guaranteed to process all FOAF files. As I've observed in my weblog before, even as much as 96% coverage is in no way good enough.
  • It encourages poor abstraction. The temptation to mix up knowledge of FOAF term semantics with the parsing would lead to messy mixing of layers, which in turn...
  • Doesn't guarantee future compatibility. Only a general purpose RDF parser can cope with all future RDF vocabularies. FOAF is intended to be used with other vocabularies mixed-in. No special purpose solution can properly take that into account.
  • There's no real reason. Memory footprint is no excuse. Even my cellphone has megabytes of memory to play with. RDF parsers can get as small as 10 kilobytes.

So I went looking for a C# toolkit for parsing RDF, and immediately encountered Drive, a 100% C# RDF parser. Drive was developed on Windows .NET but compiled painlessly under Mono. With a small amount of flicking through the API documentation and a test program or two, I was ready to go within the hour.

Together with the work I wanted to do on the Dashboard side, the whole implementation took me less than a working day. Admittedly I'm familiar with RDF processing (although I've only been programming in C# for a few weeks).

I'm glad I made the right choice and stopped trying to screw in an RDF bolt with my XML hammer. It's telling that I still consciously made the decision, though. I figure this was probably because I had no toolkit to hand in the Mono classes, and had to decide whether to add an entire RDF parser to the codebase. I can however safely say it's the last time I'll ever give this consideration.

Some XML programmers come to RDF with the question "why should I use an RDF parser?" This is the wrong way around. We should be asking anyone dealing with RDF vocabularies such as FOAF and RSS 1.0 "why aren't you using an RDF parser?" As I found out today, it takes less development time and makes your code cleaner.

Two footnotes: firstly, I should observe that some of the credit for the rapid development must go to C#. It definitely pushes my buttons as far as strongly typed languages go. C# has all the right design decisions in exactly those areas where Java annoys me. Secondly, Drive seems like a good start to an RDF toolkit, though there are several things that strike me as odd. When I've had more experience with it, I'll write a review here.

blog comments powered by Disqus

You are reading the weblog of Edd Dumbill, writer, programmer, entrepreneur and free software advocate.
Copyright © 2000-2012 Edd Dumbill