By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

"Empty" text

P: n/a
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",
cols="64")
if desc is None:
desc = ''
ta.text = desc
--------------------

The problem is that this generates the following code:

<tr>
<th>Description</th>
<td>
<textarea cols="64" name="desc" rows="8" />
</td>
</tr>

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
Jul 8 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote:
The problem is that this generates the following code:

<tr>
<th>Description</th>
<td>
<textarea cols="64" name="desc" rows="8" />
</td>
</tr>

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?
Then either Firefox is broken or you don't declare your XHTML properly and
Firefox thinks it's HTML.

Ciao,
Marc 'BlackJack' Rintsch
Jul 8 '07 #2

P: n/a
Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote:
The problem is that this generates the following code:

<tr>
<th>Description</th>
<td>
<textarea cols="64" name="desc" rows="8" />
</td>
</tr>

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?

Then either Firefox is broken or you don't declare your XHTML properly and
Firefox thinks it's HTML.
I suspect the former - we noticed exactly the same thing (can't
remember which tags we were having problems with), using the
declaration :-

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I haven't tested this again recently though.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jul 9 '07 #3

P: n/a
On Jul 9, 4:30 am, Nick Craig-Wood <n...@craig-wood.comwrote:
Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote:
Firefox is very unhappy about the textarea not having separate
opening and a closing tags. i.e. I need this:
Then either Firefox is broken or you don't declare your XHTML properly and
Firefox thinks it's HTML.

I suspect the former - we noticed exactly the same thing (can't
remember which tags we were having problems with), using the
declaration :-

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I haven't tested this again recently though.
Firefox is not broken. The XML prolog and DOCTYPE do not affect HTML
vs. XHTML interpretation--only the Content-Type does. If you are
serving a page as "text/html", which you almost certainly are, then
all browsers will parse it as HTML, regardless of prolog and doctype,
and HTML does not support self-closing tags. You need to serve the
page as "application/xhtml+xml", or avoid self-closing tags on
elements other than <img>, <br>, <link>, etc.

http://www.w3.org/TR/xhtml1/#C_3

Jul 10 '07 #4

P: n/a
Miles <se*********@gmail.comwrote:
On Jul 9, 4:30 am, Nick Craig-Wood <n...@craig-wood.comwrote:
Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote:
Firefox is very unhappy about the textarea not having separate
opening and a closing tags. i.e. I need this:
>
Then either Firefox is broken or you don't declare your XHTML properly and
Firefox thinks it's HTML.
I suspect the former - we noticed exactly the same thing (can't
remember which tags we were having problems with), using the
declaration :-

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I haven't tested this again recently though.

Firefox is not broken. The XML prolog and DOCTYPE do not affect HTML
vs. XHTML interpretation--only the Content-Type does. If you are
serving a page as "text/html", which you almost certainly are, then
all browsers will parse it as HTML, regardless of prolog and doctype,
and HTML does not support self-closing tags. You need to serve the
page as "application/xhtml+xml", or avoid self-closing tags on
elements other than <img>, <br>, <link>, etc.

http://www.w3.org/TR/xhtml1/#C_3
Ah very good - that solves that mystery - thank you!

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jul 10 '07 #5

P: n/a
On Jul 8, 5:23 pm, Jan Danielsson <jan.m.daniels...@gmail.comwrote:
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",
cols="64")
if desc is None:
desc = ''
ta.text = desc
--------------------

The problem is that this generates the following code:

<tr>
<th>Description</th>
<td>
<textarea cols="64" name="desc" rows="8" />
</td>
</tr>

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
I ran into the same problem and a workaround I found was to use either
ta.text = " " or ta.text = "\n" instead of ta.text = ''.
For my application, it did the right thing; your mileage may vary.

André

Jul 10 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.