XML "Programming Language"?
March 7, 2007 9:21 AM   RSS feed for this thread Subscribe

I maintain a program that does something complex based on a simple set of explicit commands. For example, if it were a painting robot (the truth is far more boring), you give it an XML file with elements like (angles swapped for brackets) [rectangle x="40" y="40" w="10" h="10" color="red"/] and it goes and paints it. I have some users that would like to write loops, functions, and keep variables -- but I don't want to write a state machine or interpreter. Is there some sort of language/specification that compiles a simple XML-type language into "flat" XML?

In the painting case I could let users submit a file like: [loop x=0 to x=10 step=1] [rectangle x="$x" y=10 w=10 h=10/][/loop] and some library or separate program would take that file and render a flat XML file like [rectangle x=0 .../][rectangle x=1 .../] ... [rectangle x=10 .../]. I would rather not change my program to accept anything but flat XML, but I could add a parser to it that handled all this stuff for me and spit out just the commands to my program, one after another. Sort of like a compiler that output xml elements instead of machine code.

I've looked at RELAX and XSLT, and neither seem to do what I want-- I think.
posted by neustile to computers & internet (6 comments total) 1 user marked this as a favorite
You could take a look at Jelly.

A few years ago I was forced to use Maven, the evil abomination, and the only good thing about it was the Jelly scripting language. Not sure if it's exactly what you're looking for, though.
posted by veedubya at 9:54 AM on March 7, 2007


You might look at Velocity Engine - to my understanding (i don't use it as I'm a ruby developer) it's a templating language that allows you to generate XML files (as well as others). The Java developers I know love it.

Also within Ruby, I use Builder which works basically the same way.

Hope that helps!
posted by ukdanae at 9:59 AM on March 7, 2007


XSL will do what you want, it just won't be pretty because it wasn't designed for that. You'll have to do some thinking about the structure of the provided XML "instructions" in order to make things easier on the stylesheet.

Something like:

[loop minx="0" maxx="10" step="1" y="10" w="10" h="10" /]

Could easily be handled with a template/call-template loop. Check out the XSL list, which has been helping people pound in square pegs for years.
posted by deadfather at 10:41 AM on March 7, 2007


Who's going to see the XML? XML sucks to read and write for humans (and machines).

If it were me, I'd take the simple route and give my users a language that's designed for humans to use, and translate that to whatever you need. Python as an example:
for i in range(10):
     rectangle(x=i, y=10, w=10, h=10)
...might write out [rectangle x="0" ...][rectangle x="1"...] ... x="9"] . That is, don't put the complex part in XML and expect people to parse it if you can avoid doing so. Abstract the ugly parts away so we don't have to see them.
posted by cmiller at 12:01 PM on March 7, 2007


Thanks Deadfather, ukdanae, veedubya, I will check out your suggestions over the next few days. I've never head of jelly or velocity so thanks for the tip!

cmiller: your idea of having a real language output the XML might work. I could probably make a Python class to do the serialization to XML. This would require all my users to have Python running, but they're mostly on OS X anyway. I'll float it to them!
posted by neustile at 12:35 PM on March 7, 2007


Seconding velocity. Simple, lightweight, and very easy to use.
posted by cmicali at 6:54 PM on March 7, 2007


« Older I'm looking for recommendation...   |   Prospective new employer keeps... Newer »
This thread is closed to new comments.