Tk Library Source Code

View Ticket
Login
Ticket UUID: 900041
Title: htmlparse does not supprt empty elements
Type: Bug Version: None
Submitter: nobody Created on: 2004-02-19 01:38:25
Subsystem: htmlparse Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2004-09-30 01:19:18
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2004-09-29 18:19:18
Description:
htmlparse 1.3 (as well as 2.0) does not support
empty elements of the form:

<e ... />

I think this is supported in the HTML standard.

e.g.
<list name="List1" />
<list name="List2" />
results in
   list {} {name="List1"} {}
   list {} {name="List2"} {}
rather than
   list {} {name="List1"} {}
   list {/} {} {}
   list {} {name="List2"} {}
   list {/} {} {}

The first case results in havoc for 2Tree.

A quick fix is to perform the cmd substitutions in
2 passes (a necessary evil?)

htmlparse 1.3 change (I think the Class code was
removed in later versions):

set w " \t\r\n";# white space
set exp1 <(/?)([CClass ^$w>]+)[CClass $w]*([CClass 
^/>]*)>
set exp2 <(/?)([CClass ^$w>]+)[CClass $w]*([CClass 
^/>]*)/>

set sub1 "\}\n$cmd {\\2} {\\1} {\\3} \{"
set sub2 [concat $sub1 "\}\n$cmd {\\2} \{/\} \{\} \{"]  

regsub -all -- $exp1 $html $sub1 html
regsub -all -- $exp2 $html $sub2 html

Any comments?

Tony Grimm
[email protected]
User Comments: andreas_kupries added on 2004-09-30 01:19:18:
Logged In: YES 
user_id=75003

I got another report about this, see 

http://sourceforge.net/support/tracker.php?aid=1034580

This one came with code. It changed the empty tag into a
single closing tag. Which I considered wrong. However based
on that I was able to create something which transforms an
empty tag into a pair of opening and closing tag in the
event sequence. I.e. something like

    <a href="foo"/>

would be handled as if the input had been

    <a href="foo"></a>

This is IMHO the most sensible approach to real-world data
using empty tags.

Committed my changes to head, see the other report for details.

mic42 added on 2004-02-25 06:28:35:
Logged In: YES 
user_id=302287

See:
http://www.w3.org/TR/2000/REC-xhtml1-20000126/#guidelines
C.3 for the suggestion of W3C regarding empty elements with
non empty content model.

mic42 added on 2004-02-25 06:18:31:
Logged In: YES 
user_id=302287

The HTML Standard 4.01 does not support <list name="List1"
/>, this is XHTML Syntax and for XHTML one is better off
using a true XML Parser like TclXML or tDOM.

Empty tags do not have closing tags, so it is correct if no
closing tag appears in the result list.

Fixing the class code looks like the wrong thing to do, it's
2TreeCallback that needs fixes, the tree generation.

As <list> isn't a valid html tag it should be ignored by
2Tree anyway.

If you did it with <li /> and it breaks, thats an other matter.

nobody added on 2004-02-19 08:42:17:
Logged In: NO 

Oops, wrong mailing address.

Should be [email protected] -- Sorry