HTML::Element::Table, HTML::Element bug 
Author Message
 HTML::Element::Table, HTML::Element bug

[email cross posted to comp.lang.perl.modules]


> Matthew,

> I saw your posting to clpm and downloaded HTML::Element::Table.  It is very
> nice and certainly much better than what I had been using.

Thanks...glad you like it.

> One thing I noticed is that the text in the table cells as it comes out
> of as_HTML() is encoded for HTML entities.  I haven't looked at your code
> too much, but presumably there are internal reasons for doing this.

Yup.  This is an annoying "feature" of the HTML::Element class.
HTML::Element uses HTML::Entities (or misuses) when it processes
text data in the as_HTML() method.  For simple text content,
it first processes the text with the following call:


If I understand encode_entities(), when you pass it a character
list the method limits encoding to only those characters.
Thus, in the case of HTML::Element, it becomes impossible
to ever have a "&code;" in your HTML stream.  If you pass the
literal character code (such as \240 for &nbsp;), then the
actual character is placed in the HTML stream, which is not
necessarily what you want.

It's a combination of misuse and hand holding that I'm not
particularly happy with.

>   $t = new HTML::Element::Table(maxrow => $total_rows+4, maxcol => $total_cols) ;
>   $t->cell(0,0)->replace_content("<a href=/some/page.html></a>") ;
>   $output = $t->as_HTML() ;

I recommend using HTML::AsSubs to accomplish this.  With that, the
replace_content line becomes:

   $t->cell(0,0)->replace_content(a({href => "/some/page.html"}));

Passing literal HTML will not work, unfortunately.  On the plus side,
however, if you've been manipulating an HTML::Element tree, you can
just pass the element tree directly in:

   $e = a({href => "/some/page.html"}); # pretend its complex

> Then again, maybe there is a good reason for not doing this
> that I am overlooking.

A necessary and annoying reason, if not a good one.  One might
take the purist stance and say "HTML::Element or bust", but
personally I find it convenient many times to pass some literal
HTML into my output stream.  Disallowing control sequences
in HTML element trees seems like a bug to me.

Matt Sisk

Mon, 16 Apr 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. HTML::Calendar, HTML::Element::Table - DISCUSSION

2. Questions re HTML::Element and HTML::TreeBuilder

3. detect text segment and HTML::Element in HTML::TreeBuilder

4. HTML::Element bug or flaw (entities) ?

5. HTML::Element bug or flaw (entities) ?

6. HTML::Element::extract_links not grabbing frame sources

7. HTML::Element

8. using HTML::Element optional end tags

9. HTML::Element - traversing content only

10. What is an HTML::Element

11. problem with HTML::Element

12. HTML:Element/Parse/Tree question


Powered by phpBB® Forum Software