By Peter Bell

Adventures in XML

My in-house framework is going XML! I'm using it at a fairly high level of abstraction to describe objects, properties, relationships, screens, actions, validations, transformations and the like, replacing most of the coding for an application with DSLs using an XML concrete syntax. This posting looks briefly at why I'm using XML and the next one will consider some the issues when developing an XML schema . . .

As most reader of my blog will know, while I have always defended the use of XML, it is has been a case of intellectual honesty rather than preference. I don't like angle brackets. They make my eyes bleed :->

So, why am I going to use XML as a concrete syntax for my DSLs? Firstly because it means I'll be able to reuse config files between different programming languages. As well as ColdFusion, I should have at least a Ruby and possibly a Java implementation of my framework by early next year and I want to make sure that most applications can be ported between languages without having to change any code.

Secondly, I'm really just using it as an interface to lower the coupling between my feature modeler and my framework. I'll still be keeping all of the statements in a database to make it easier to select and configure features from a database of pre-build statements in the various DSLs. The XML just makes a convenient output format for the feature modeler, so while there will be XML, at least human beings won't actually have to write it by hand (ugghh - what a thought :->).

And finally, all the usual stuff about free parsing, the ability to validate against a schema and so forth. If I had more time and human beings were really going to have to create these files, I'd bite the bullet and write a parser in ANTLR using my own custom syntax (from what Mark says, ANTLR 3 rocks!). If I didn't need to support multiple 3GLs, I'd stick with my in language APIs, but for this use case, XML fits just right. Of course, it is still being consumed by config beans which then do a lot of automagic to make sure a little configuration goes a long way. For example, you don't have to describe how to wire your beans together. You just describe the object model and the config bean is smart enough to know that your service methods and business objects need to have a DAO mixin injected and so on.

Thoughts?

Comments
And our fearless hero, machete in hand, hacks through the XML jungle...

Is YAML not supported enough to consider using? Not that I'm that anti-XML ... just wondering really. As you said, no body really needs to look at these things, so who cares what it looks like? Compile it SFBC - Systems Forge Byte Code for all anyone cares, right? =)
# Posted By Sammy Larbi | 6/10/07 12:55 PM
Actually, I figured since it doesn't really matter, why not go for the option with the greatest tool support. If I ever find myself hand writing these things, I'll go come up with a nice clean custom syntax and write a simple transformation that'll turn it into the XML so I don't have to look at it(!), but this does mean that if I want to do XSLT for model:model transforms or whatever I'll have all my metadata in arguably the most supported syntax for that kind of work.
# Posted By Peter Bell | 6/10/07 1:24 PM
That's what I meant by is YAML not supported enough? I haven't looked into it enough to know for sure, but the concept seems like it would be great for DSL use if there is enough tooling to support it.

Of course, that whole semantic whitespace issue crops up in using DSLs in YAML.
# Posted By Sam | 6/11/07 9:23 AM
I personally quite like YAML:
http://www.yaml.org/start.html

However as you mentioned, the meaningful whitespace (while nice) is a bit of a pain for generation, and then I'd have to find some kind of YAML -> XML tooling to take advantage of any XML specific features like XPath, etc.

I'll probably play with this some time, but only when my eyes start bleeding form the angle brackets :->
# Posted By Peter Bell | 6/11/07 10:02 AM
Speaking of XML and eyes being poked out by angled brackets, one of the sessions at NFJS is described as:

A wise man once said, "XML is like lye. It is very useful, but humans shouldn't touch it." If you've had to incorporate XML into your project by hand, you have probably been burned by getting too close. NetKernel turns this wisdom on its head and encourages you to use XML like the liquid data stream you want it to be. Imagine the simplicity of REST married to the power of Unix pipes. Come see how this open source / commercial product built on a compelling modern architecture can be used to create, manipulate and transform XML.

Might be worth checking into (not necessarily for this, but in general).
# Posted By Sammy Larbi | 6/11/07 11:04 AM
Looks cool - tnx!
# Posted By Peter Bell | 6/11/07 11:31 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.