Merry XMLmas

10.12.05 | 4 Comments

The last of the XML jokes, I swear. I managed to get around my problems from the post of last week and get at what I’m really trying to do: blast unedited HTML into the middle of an XML without any errors.

After a few false starts I settled on the method I’ve been using for months – make the HTML part of the XML itself, and display it using the proper codes in the template. I wasn’t exactly hot for this solution, much less married to it, because you can have valid HTML that doesn’t conform to the specifications for XML.

For example, take the <br> tag. Perfectly valid HTML. But XML requires all tags to be terminated, so in XML this should read <br/>. Same thing with <img> and lots of other tags. And if you make a typo? Crapville. As it happens there’s not a handy way to enforce this, and if you mistype even one tag the XML programming interface pukes on you. Which is not just discouraging but smells bad, too.

One solution is to define the HTML as a CDATA section, so it’s not evaluated as markup. The problem is that my templates don’t display the ouput correctly. They display it as text instead of markup (it looks like <b>this<b/> instead of this).

Happily, I figured it out today. If the template tags that dump the CDATA are inside other tags, such as an ‘if’ command, they don’t work, but if I put them in a separate template and invoke that – hey presto, it works.

I can see your attention wandering, so I’ll shut up now. But let me just say, this is cool, because now I can open up some of the apps I’ve been working on without worrying about the users (aka ‘lusers’) mucking up the markup.


have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>