obscure problem using elementtree to make xhtml website

David Smith dns4 at cornell.edu
Thu Sep 3 10:28:50 EDT 2009


Lee wrote:
> Elementtree (python xml parser) will transform markup like
> 
> <tag boo="baa"></tag>
> 
> into
> 
> <tag boo="baa" />
> 
> which is a reasonable thing to do for xml (called minimization, I
> think).
> 
> But this caused an obscure problem when I used it to create the xhtml
> parts of my website,
> causing Internet Explorer to display nearly blank pages. I explain the
> details at
> 
> http://lee-phillips.org/scripttag/
> 
> and am writing here as a heads-up to anyone who might be using a
> workflow similar to mine: writing documents in xml and using python
> and elementtree to transform those into xhtml webpages, and using the
> standard kludge of serving them as text/html to IE, to get around the
> latter's inability to handle xml. I can't be the only one (and I doubt
> this problem is confined to elementtree).
> 
> 
> Lee Phillips

It's not just Elementtree that does this .. I've seen others libraries
(admittedly in other languages I won't mention here) transform empty
tags to the self-terminating form.  A whitespace text node or comment
node in between *should* prevent that from happening.  AFAIK, the only
tag in IE xhtml that really doesn't like to be reduced like that is the
<script > tag.  Firefox seems to be fine w/ self-terminating <script />
tags.  At any rate, I tend to put a comment node in between the begin
and end to prevent the reduction:

<script src=" ... " type="text/javascript"><!-- --></script>

--David



More information about the Python-list mailing list