Thursday 23 May 2013

Balisage 2013

My paper was accepted for this year's edition of Balisage, the markup conference held in Montréal, Canada in August every year. I'm going to talk about profiling XML using an abstraction level to avoid the problems associated with using plain values.

I'm really, really excited and honoured. 

Sunday 12 May 2013

Micro XML and Namespaces

Micro XML is an attempt by James Clark, John Cowan and Uche Ogbuji to simplify XML and get rid of all that extra baggage that currently surrounds it. DOCTYPE and PIs are both removed, UTF-8 is mandatory, draconian error handling is no longer a must, and--perhaps most controversially--namespaces are gone, too.

Uche Ogbuji held a brilliant talk about Micro XML at the recent XML Prague 2013 conference, so rather than reiterating his arguments, I suggest you watch the presentation once it's made available at the XML Prague website.

What I did want to comment about is this namespaces business. Of everything proposed in the Micro XML spec, the removal of namespaces is clearly the most controversial, as indicated by the many tweets following Uche's talk. But should you be upset? I mean, really?

I've done some fair bit of XML stuff involving namespaces lately (yes, I know, there's no way to avoid it, really). There's a Relax NG compact schema that I wrote that uses several, including a default "". There are conversions from external XSD-based XML to that Relax NG-based XML using XSLT 2.0, and there are conversions from the Relax NG schema to (an obviously not namespace-aware) DTD to satisfy the needs of an editor that does not know what Relax NG is. (And I can't bring myself to write XSDs; they are the spawn of Satan.) And there are XProc-based pipelines that glue these things together, and they obviously need to be aware of the namespaces in addition to the ones they use themselves.

Lots of namespaces, in other words. And I'm not exaggerating when I tell you that a vast majority of the problems I had and the weirdness I encountered had to do with namespaces.

Nothing coming out from the transformation? A forgotten implied default namespace in the source XML. Namespace declarations in the target XML messing up validation? That same default namespace. The wrong prefix for the XLink namespace in the target XML? No explicit namespace declaration in the source. An unwanted and disallowed XLink namespace declaration being complained about in the root element of an XML document in the process of being checked out from a repository? A web service helpfully adding a seemingly missing namespace declaration to a root element into content in a SOAP envelope, resulting in a document that could not be opened but that did not show any problems in the repository itself, only on its way out...

These are just a few select examples from my plight, and while I may have some of the details slightly wrong here, you probably get the idea. The list goes on.

And why is this all happening? Because someone at some point thought that wouldn't it be nice if you could share your XML with everyone on the globe with no risk of name collisions and clashing semantics? Wouldn't it be cool if the conflicting schemas could all be identified using a URI? We could have a throwaway name prefix attached to that URI and implement processing that could hide the prefix for the end user, simplifying things further...

Of course, that someone's idea of backwards compatibility was simply that to a DTD, the revolution would be hidden in an extra attribute and an element type name containing a colon.

The fact is that I have yet to be helped by namespaces when using XML from the other side of the globe. In fact, I have yet to encounter a situation where I need to process unknown XML where potential clashes in semantics can do harm without me spotting the problem well in advance and taking care of it. The fact is that I don't often need to use XML from the other side of the globe, out of the blue. It tends to happen in a context, in a controlled manner.

But when I do process that XML, knowing full well the source semantics and how they can map to my needs, it is always the namespaces that cause me grief.

Namespaces are among the least understood features of modern-day XML and among the most abused. The tools range from helpful to disastrous to completely ignorant or just plain wrong, and there are as many reasons for this as there are XML parser implementations out there. You know right from the start that you will have problems, so you'd better resupply the medicine cabinet well in advance or get ready for that headache.

So, Micro XML? Yes, please. Now?

I Did Some Code!

Yesterday evening, I had an itch that needed scratching.

I was lacking some convenience features in an XMetaL-based authoring environment I am finalising for a client. There is a structure in the DTD that I am presenting as a table using some CSS in the editor, which makes perfect sense since it's always going to be formatted that way when published. Presenting a structure as a table in XMetaL, however, means that XMetaL will hide the elements defined as table rows; it's a side effect of how tables are presented in the editor and most editors have similar problems.

But where HTML or CALS tables are supported by XMetaL's customisations for tables (with adding or deleting rows or cells), my custom structure isn't. It only looks like a table, it isn't one because the actual semantics are quite different when studied in detail, and so the standard table functionality is not available. I needed custom code for my table-like structure.

Under normal circumstances, I'd simply walk over to a colleague, describe my problem and let him do his magic. There is something slightly twisted and evil in any object-oriented programming, and I usually want no part of it. You have an "object" that, depending on things you very often can't see or would not fully fathom anyway, have special magical abilities you can use to solve your problem, which is all fine and well, but very often, you also have a seemingly similar "object" that doesn't have those magical abilities. It instead possesses different ones, and because you are but a learner and only borrowing the magic wand, you eventually leave it be.

It's evil.

But this time, I thought "how hard can it be?" and started writing, aided by other people's efforts, an XMetaL Programmer's Guide, and an Ouija board (no, not really; just Notepad ++). Soon, those magical objects appeared with their special abilities, and I started invoking magic using while loops and other features I know from scripting languages. Remember Mickey Mouse in Fantasia? That's me, thinking "how hard can it be?"

The difference was that the magic here is better protected. Mickey never had access to Ctrl+Z.

Two hours later, I had my little convenience functions. The sorcerer has yet to return, but I am confident that my code works. The broom does what it's told to do.