A couple of weeks ago Kurt Cagle posted XQuery, The Server Language on XML.com. I like this article a whole because it:
- Explores how XQuery is more than a query language
- Shows how XQuery is actually THE server-side scripting language to create HTML
- and contains this very nice example of how things used to be:
$buf ="<html><head><title>".$myTitle;
$buf += "</title><body>";
$buf += "<h1>This is a test.</h1>";
$buf += "<p>If this were an actual emergency, we'd be out of here by now.";
echo $buf;
Yup - back before XQuery, in the days when your dad had to ride his bike uphill both ways to school and people didn't even have answering machines (you had to just call back later) . . . this is how you had to make HTML.
Creating strings to represent elements is fraught with danger - while the above works, its hardly valid. But it was the only simple choice (the other options, as Kurt points out, were Java pipelines with multiple moving parts).
Aren't we glad we have XQuery?
This sort of thing is now done in an entirely XML-centric environment where you just create elements instead of strings you hope will work out:
let $mytitle := "title from input"
return
<html><head><title>{$mytitle}</title></head>
<body>
<h1>This is a test.</h1>
<p>If this were an actual emergency, we'd be out of here by now.</p>
</body></html>
This is a very liberating moment. Here is a scripting language, built to create XML - the language of the web. There is no impedance mismatch between text, objects, and elements . . . its all about the tags.
So celebrate the XML independence by getting a good XQuery engine like MarkLogic Server and bring a little XQuery into your content applications.
But be careful, its pretty addictive . . . luckily, these days you can just let the answering machine pick up.
Comments