Friday, 2 November 2007

AtomPub services and auto-detecting the schema type of XML based collections & feeds

AtomPub rocks, its an excellent way of building RESTful services that are easy to discover, consume & they avoid the developer having to figure out for themselves a nice RESTful protocol for reliably exposing resources with all operations being idempotent etc. (Most developers miss that bit out :). I like the extra constraints AtomPub adds above REST; less mistakes for us developers to make :)

The content of Atom feeds can be text, XHTML or XML (entries can also link to arbitrary media types too). When using XML for the atom:content, it might be nice to be able to discover the schema up front - which could help tooling / UIs / frameworks.

e.g. from the AtomPub service document when looking at each collection provide an easy way to get the schema document. I've been googling to see if anyone has done such a thing; I've not yet found an obvious answer.

One idea is to use content types; something like
<collection>
<accept>application+xml; type=someSchemaURI</accept>
</collection>
another could be to add a new kind of link to the feed
<feed>
<link rel="content-schema" type="application/relax-ng-compact-syntax" href="/schemas/something.rnc">
...
</feed>
I guess a tool could always just look at the content of the feed and look at the namespaces then do some out of band google search for schemas for those namespaces :) but it might be nice to be able to make it a little easier to auto-detect the schema - particularly as AtomPub has gone to great lengths to make everything else (system, workspace, collections, entries) easily discoverable and navigable.

Anyone else figure out a neat way to expose the schema of the XML inside the content for collections or feeds?

5 comments:

Dan Diephouse said...

I think another option would be some type of features/policy approach:

http://netzooid.com/blog/2007/09/25/atompub-ws-policy/

All I want is a way to link mimetypes and schemas. APP is so close, but so far...

James Strachan said...

Yeah! If we there were a standard mime type -> schema mapping we'd be sorted. This would also work great in HTTP too!

Its a bit of a hack but I wondered about just hacking MIME to be

application/xml; schema=someURI

or in the case of SOAP/Atom wrapped stuff something like

application/atom+xml; schema=someURI

Dan Diephouse said...

The problem with mime types (at least if you're transmitting them as an HTTP header) is that you can't figure out any of this stuff ahead of time. Granted this could work in the APP services document like you describe. It'd be great though if there was just a generic way to query what resources were available, what mime types the resources could be represented as, and how those mime types related to some description/schema (if they do relate at all).

Stefan Tilkov said...

A while back, Sanjiva and some other folks from WSO2 got in touch to propose something very useful regarding MIME types and their connection to XML schemas. I have no idea why they didn't make it public ... it might make sense to follow up with them.

WebMosaic said...
This comment has been removed by a blog administrator.