DocBook Tiny

Volume 8, Issue 142; 05 Nov 2005; last modified 08 Oct 2010

Want DocBook with just five elements? You got it.

RELAX NG lends itself to more modular schema designs than DTDs ever did. The DocBook V5.0 grammar is built from modules and it would be fairly easy to construct a new top-level driver file that didn't include some modules. For example, if you didn't want msgset, you could just leave out msgset.rnc.

But an even simpler answer occurred to me the other day. It's a little bit “brute force”, but that's ok. Construct a grammar that includes the base grammar, sets the start, and sets to notAllowed all the elements you want to exclude:

include "http://docbook.org/xml/5.0b1/rng/docbook.rnc" {
   start = db.book|db.chapter|db.article

   db.abbrev = notAllowed
   db.abstract = notAllowed
   db.accel = notAllowed
   db.ackno = notAllowed
   …
}

That's DocBook with just five elements. Want to allow emphasis? Just delete the line that makes it not allowed. You can add any other elements the same way until you have just the DocBook you always wanted.

Any document that's valid according to your “tiny” grammar will also be valid according to full DocBook. The only thing you have to watch out for is constructing a grammar that won't validate any document at all. For example, if you allowed book but not title, you could never validate a book because a title is required.

Comments

Coolest. Thing. Ever. I hope this RELAX NG thing is going to be really big.

—Posted by Giulio Piancastelli on 06 Nov 2005 @ 12:17 UTC #

It's great to see how easy it is to provide modular document types. I wish docbook 5 would use that technique and organize its markup into such modules, such that things like modeling-like markup (function, class, classsynpsis, etc.) would all end up in their respecitive 'profile', so it would be easier to define a 'docbook-core' and a set of 'profiles', which users could select individually. That would facilitate discussing modifications and additions to individual profiles.

—Posted by Stefan Seefeld on 06 Nov 2005 @ 03:52 UTC #

I think that removing unnecessary elements is more usable way of doing things. Building the schema from an individual modules means that you must be very careful about content models. You can do this in RNG using combine construct, but many elements would fall into several modules (especially in case of inlines).

To make customization easier it is possible to group notAllowed elements together and create small grammars that can be included to switch off whole set of related elements.

—Posted by Jirka Kosek on 06 Nov 2005 @ 09:36 UTC #

Is this the answer to the 'simple' docbook that came up on the apps list some time back?

I guess the use case is people wanting to generate docbook to X stylesheets, beaten by the recursion and complexity of the current content models?

Another benefit of moving to Relax NG Norm?

—Posted by Dave Pawson on 07 Nov 2005 @ 12:16 UTC #

I've been handling my customization layers this way for several months. Since I use oXygen, I can use the RelaxNG validation right away. I can also transform to a DTD very easily. XML Hack #78 describes this process in detail. And I agree with the earlier comment: Best thing ever!

—Posted by Scott Hudson on 07 Nov 2005 @ 05:18 UTC #

very cool. What tool would you use to edit such a micro vocabulary?

—Posted by Maurice Martin on 25 Apr 2006 @ 01:45 UTC #

I'd use Emacs, as ever. But any RELAX NG aware editor should work, and there are more of them all the time.

—Posted by Norman Walsh on 25 Apr 2006 @ 09:51 UTC #