[Zope] Re: Using ZPT to create XML - early processing

Evan Simpson evan@4-am.com
Sun, 16 Mar 2003 10:36:59 -0600


Ed Leafe wrote:
> <?xml version="1.0" ?>
> <!-- RSS generated by Zope 2.6.1 on Sat, 15 Mar 2003 13:29:11 EST -->
[...]
>     If I try to use TAL in the comment line, it doesn't get processed. 
> It seems that ZPT will not process TAL content within the comment.
[...]
>     So is there any way to generate commented XML using TAL?

This works:

<tal:comment
   xmlns:tal="http://xml.zope.org/namespaces/tal"
   define="now python:DateTime().strftime('%e %b %Y')"
   replace="structure string:&lt;!-- $now --&gt;" />

TAL doesn't process comments, so you do have to generate the entire 
comment.  The XML parser doesn't like unescaped '<>&' characters in 
attribute values, so you need to escape them.  Finally, when generating 
XML you need to make sure there's a 'xmlns:tal' declaration on or around 
your tag -- since there's no surrounding tag in this case, we have to 
put it on the tag itself.

Cheers,

Evan @ 4-am