Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: HTML::TreeBuilder and HTML4.01 empty elements

by rhesa (Vicar)
on Jul 09, 2008 at 11:54 UTC ( [id://696432]=note: print w/replies, xml ) Need Help??


in reply to HTML::TreeBuilder and HTML4.01 empty elements

The relevant code in HTML::Element->starttag is this:
if ( scalar $self->content_list == 0 && $self->_empty_element_map- +>{ $self->tag } ) { return $tag . " />"; } else { return $tag . ">"; }
Since hr, br, and img never have children, the first condition is always true. So we'll have to tweak the second one to get the output you want.

Here's a quick hack that works:

#!/usr/local/bin/perl use strict; use warnings; use HTML::TreeBuilder; my $h = HTML::Element->new_from_lol( ['html', ['hr'], ['br'], ['img', {src => 'pic.jpg'}], ], ); { # suppress xhtml /> on these tags: my @noslash = qw/ hr br img /; # by temporarily pretending the can have content: local @HTML::Tagset::emptyElement{ @noslash } = 0; # and have optional end tags: local @HTML::Tagset::optionalEndTag{ @noslash } = (1) x @noslash; print $h->as_HTML; } __END__ <html><hr><br><img src="pic.jpg"></html>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://696432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found