2

We have a requirement in which we need to convert a given rdf file into a specific xml file. So we have three inputs RDFS file, RDF file and XSD file. With these we need to create XML file (which should conform to the XSD) having the data of the RDF file. The RDF schema contains simple, complex, relation entities. The relations defined in the RDF are different from the relations defined in the XSD.

We see couple of ways of implementing the same:

  1. Create an XSLT defining the logic for converting the RDF file to XML file.
  2. Build a custom C# app. for doing the same (using RDF libraries like LinqToRDF etc.)

Please guide regarding which option would be better and any pointers for the same.

Regards,

Jayanta Dey
  • 307
  • 1
  • 9

2 Answers2

0

First of all: It's not a "either ... or" decision. You can easily combine an XSLT transformation with custom C# code. That said:

In my experience XSLT is a great choice, if the transformation does not contain too much logic. It's easy to rename tags, to flatten or rearrange hierarchies, ... using XSLT, but it can be come nasty if you need "if-then-else" logic like "create tag A if value of ... but only if ... else create tag B".

The sentence

The relations defined in the RDF are different from the relations defined in the XSD.

sounds like a complex transformation, which involves quite some "if-then-else" and "look up" logic. In that case I would probably go for a more C# centric solution.

Achim
  • 15,415
  • 15
  • 80
  • 144
  • Yes, the transformation may require implementing complex logic and a C# based solution would be better. But I am not sure how to proceed in this direction. I tried using LinqToRDF library to parse the rdf file, with that I can get all the statements, but is it possible to retrieve the RDF information in form of classes and objects (like how we deserialize an xml)? Can we generate these classes from rdfs file (like using tool similar to xsd.exe)? – Jayanta Dey Apr 12 '11 at 09:22
  • That is actually what LinqToRdf was designed for, there is a tool call RdfMetal provided to generate .Net classes from your RDF or OWL ontologies. Unfortunately the documentation around how to do this is quite poor, and be aware that the project was abandoned some time ago by its author and is not actively maintained or supported – RobV Apr 12 '11 at 14:12
0

XSLT is generally a bad idea for converting RDF/XML into other formats because the same RDF data can be encoded in RDF/XML in different ways.

So unless your RDF/XML input is tightly controlled a pure XSLT transformation is usually quite difficult and hard to maintain.

For C# manipulation of RDF you might want to try dotNetRDF (disclaimer - I develop the library) which gives you an API for working with RDF at the Triple level. If your RDF has regular repeating structures in it then the easiest way to extract that data will be to use SPARQL queries to get the data of relevance to you out of the RDF. Once you have the results (which are similar to a DataTable in structure and can be cast to a DataTable if that is easier for you to work with) you can generate your XML file as desired.

If this looks like it might be a viable option for you then feel free to drop me an email on the project mailing lists if you want any help/advice.

RobV
  • 28,022
  • 11
  • 77
  • 119