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

Ed Leafe ed@leafe.com
Sun, 16 Mar 2003 14:33:46 -0500


On Sunday, March 16, 2003, at 11:36  AM, Evan Simpson wrote:

> 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.

	That makes sense, but it still doesn't seem to work when it's located 
at the very top of the XML document, before the root element. I have 
the <?xml version="1.0" ?> line, followed by your suggestion, followed 
by the root element, and I get the following error:

	Compilation failed
	xml.parsers.expat.ExpatError: junk after document element: line 8, 
column 0

Line 8 is the line containing the root element. If I place that exact 
same line *after* the root element, there is no problem.

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com