Xampl, re: "XML data bindings, static languages, dynamic languages"

In response to XML data bindings, static languages, dynamic languages Bob Hutchison posted some thoughts. As I used Amara as the kernel of my demonstrations, Bob used his project xampl as the kernel of his. He introduces xampl in another entry which was inspired by my own article on EaseXML.

Xampl is a an XML data binding. As Bob writes:

Secondly, there are versions of xampl for Java and Common Lisp. I’ve got an old (summer 2002) version for Ruby that needs updating (I wrote the xampl-pp pull parser to support this experiment).

Bob says that Xampl also deals with things that Elliotte Harold mentions as usual scourges for Java data bindings: mixed content, repeated elements, omitted elements, and element order. Of course these things should be food and drink to any XML tool, and I'm glad folks are finally plugging such gaping holes. Eric van der Vlist is also in the game with TreeBind, and it seems some Java tools try to wriggle out of the pinch by using XQuery.

Based on Bob's snippets, Xampl looks handy. Rather verbose, but no more so than Java pretty much requires. One thing that strikes me in Bob's examples is that Xampl appears to require and create a bogon namespace (http://www.xampl.com/labelsExample). It seems maybe it has something to do with Java packaging or something, but regardless of the role of this fake namespace, the XML represented by Xampl in Bob's snippets is not the same as the XML in the original source examples. An unprefixed element in a namespace is of course not the same thing as an element in the null namespace. I would not accept any tool that involves such a mix-up. It's quite possible that Xampl does not do so, and I'm just misunderstanding Bob's examples.

Bob provides Xampl code to match the EaseXML snippets in my article. Similarly to how EaseXML requires Python framework code, Xampl requires XML framework code. Since "XML situps" have been on the wires lately, they come to mind for a moment, but hey, if you're already processing XML with Xampl, I suppose you might not flinch at one more XML. I will point out that Amara does not require any framework code whatsoever besides the XML itself, not even an XML schema. It effectively provides dynamic code generation.

Xampl turns XML constructs into Java getters, e.g. html.getHead(). Amara uses the Python convention of properties rather than getters and setters, so you have html.head, and you can even assign to this property in order to mutate the XML. Xampl looks neat. The things that turn me off are largely things that are pretty much inevitable in Java, not least the very large amount of code generated by the binding. It supports XPath, as Amara does, and provides a "rhino" option to expose XML objects through Javascript, which offers you a bit more of the flexibility of Python (I don't know how much overhead to expect from Javascript through Java through XML, but it's a question I'd be quick to ask as a user).

It's good to have projects such as Xampl and Treebind and Nux. I'd rather use Python tools such as Amara, Gnosis and GenerateDS, but Java has the visibility and it's good for people to be aware that XML does not necessarily require greater imprisonment of expression than what comes with the application language. You don't need to accept crazy idioms and stifling limitations in matters as fundamental as mixed content and element ordering. XML and sanity can coexist.

[Uche Ogbuji]

via Copia
2 responses
A few quick comments:



1) verbose -- yes, Java is Java; the JavaScript, Common Lisp, and (old) Ruby versions look like those languages, and are correspondingly less verbose.



2) namespaces -- These are the links to Java packages (or the corresponding concept in the other languages). I didn't want to get into the details of how this mapping works in an introductory article. Basically the generator needs to know what package to put things into so there has to be a mapping from a namespace to a package. Currently you can resolve "" to a package -- I wanted to get the typical use (which is in a large system and so, in Java, it will be broken into different packages). There is also a way to specify a 'default' namespace for generation.  As I say, this is for the generation phase only. When you are actually running there is no need to specify a namespace in the XML, xampl will work it out (though it is the programmers responsibility to resolve ambiguities).



3) Xampl only requires XML for the configuration but even that is optional, you could have written it in either Java or JavaScript in the Java version of xampl (or CL (or sexpr soon) in the CL version, Ruby in the Ruby version).



4) From my point of view xampl doesn't require framework code, it is framework code... and I'll argue that that is a Good Thing.



5) I've considered dynamic code generation for CL and Ruby but I've not quite made up my mind on this one. I don't know if I can make that fit with the rest of what xampl provides.



6) I have not yet said what xampl is really doing, by the way. This binding stuff is incidental, in other words, it is not the primary purpose of xampl.



7) Rhino compiles to Java byte codes, so it isn't as bad as a reasonable person might imagine. It is faster than Ruby for what we do with it, don't know about in general -- Ruby is more than fast enough for what we do with it. The overhead of switching between Java and JavaScript is very small when running, a lot of that is handled at compile time (that's what the 'rhinoizing' stuff is all about -- as far as I can tell, the typical case is a method call, though sometimes you have to poke around in JavaScript's world of prototypes and scopes to find things).



8) From my point of view one of the nice side effects of this recent trend to accept dynamic languages such as Python, Ruby, JavaScript, even Common Lisp and Smalltalk is that some of the crazy binding schemes in Java can be seen to be crazy :-)



These comments are briefer than I'd like them to be, but I have time constraints due to work that have to come first today. I've duplicated these comments on my weblog and will update that post to point at the expanded comments. This is where trackbacks and pingbacks came in handy -- to bad they are pretty much useless these days because of spam.
Bob,



Agreed on (1) and (8).  Useful clarifications in (2), (3), (5) and (7) .  Not sure I understand (4), except maybe as a consequence of (3).  Not sure what to do with the mystery in (6) except shrug.



And yeah, I wish I could rely on trackbacks as well :-(