"Empty" text

Jan Danielsson jan.m.danielsson at gmail.com
Sun Jul 8 22:23:20 CEST 2007

Hello all,

   I'm using mod_python+ElementTree to build XHTML pages. But I stumbled
across this problem:

def foo(req, desc = None):


   tr = ET.SubElement(tbl, "tr")
   th = ET.SubElement(tr, "th")
   th.text = "Description"
   td = ET.SubElement(tr, "td")
   ta = ET.SubElement(td, "textarea", name="desc", rows="8",
   if desc is None:
      desc = ''
   ta.text = desc

   The problem is that this generates the following code:

              <textarea cols="64" name="desc" rows="8" />

   Firefox is very unhappy about the textarea not having separate
opening and a closing tags. i.e. I need this:

              <textarea cols="64" name="desc" rows="8"></textarea>

   I understand the opitmization ElementTree is performing; but it seems
there are cases when it is not the proper thing to do. Is it possible to
 force ElementTree to output the XHTML code I need it to?

Kind regards,
Jan Danielsson

More information about the Python-list mailing list