Home Login Create account Contact Help
Close

Login to your account

Other Options

Comments feed

In response to XML or Text for Python Templates?

There are a number of (very good) templating systems and languages available for Python. They fall in to one of two camps; either they are XML based, like Genshi, or they are text based, like Mako. Most programmers favour one or the other, but there is far from a consensus over which is better.

I'd like to use this debate to gather reasons for using one over the other in the context of web development. I suspect there will be no clear winner, but it should serve as a useful resource for those faced with the decision!

...

NB. You can post code with the [code] bbcode tag. Many languages are supported. e.g.

[code python]

print "Hello, World!"

[/code] 



Simon Willison argues for "XML"
Mon, 15 Oct 2007 by simonw
Rank 3. Average +0.8 ( 6 votes )

If your output is XML, it makes sense for your input to be XML as well. XML template engines can guarantee that their output will be well-formed XML; text engines can only produce valid XML if the templates authors are incredibly careful, and can't gaurantee well-formed output. If your application is ouputting mainly XHTML, RSS and the like an XML template engine is a really good idea.

Paddy comments...
Mon, 15 Oct 2007 by paddy3118
Simon, non-XML templating engines can create just as well-formed XML/X HTML output. If you drop the strict adherence to XML for templating then it allows you more freedom in developing a templating language syntax that is easier to maintain as well as program in.
Simon Willison comments...
Mon, 15 Oct 2007 by simonw
According to Paddy:

Simon, non-XML templating engines can create just as well-formed XML/X HTML output.


I'm certainly not saying it's impossible to produce well-formed output in non-XML engines, just that XML engines make it easier to do so with a much higher confidence that you're going to get it right. If the template's valid XML, the output will be valid XML. With non-XML engines you could have a valid template that produces invalid results when combined with a certain set of unexpected data.


Return to debate