Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by rhesa (Vicar)
on Jul 09, 2008 at 11:54 UTC ( #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
Node Status?
node history
Node Type: note [id://696432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2020-09-24 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (132 votes). Check out past polls.

    Notices?