Update: Saw GrandFather's reply. There is some misunderstanding. I guess that that was my fault, and I could have expressed myself more clearly. I have never doubted the merit of his code. The intention of this reply was/is not about whether his orginal HTML was valid. What I am saying is that, as_html converts a valid document to an invalid document, and that is a bug. To prove that, I needed a valid HTML document (in a more strict sense) that can pass the validation service, and that's all why I modified the original code. Otherwise, both HTML's before and after convertion fail the validation, and I cannot prove my point. No worries, GrandFather ;-)
=========================================
This is a bug, by HTML 4.01 specification. You do not need to be familiar with the specification, we can use W3C validate service to verify those HTML documents in this reply.
I modified your code a little bit to contain a valid HTML document. The HTML document passed W3C validation as tentatively valid.
use strict; use warnings; use HTML::TreeBuilder; my $data = do {local $/ = ""; <DATA>}; my $tree = HTML::TreeBuilder->new; $tree->store_comments(1); $tree->store_declarations(1); $tree->parse ($data); $tree->eof (); print $tree->as_HTML(); __DATA__ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>My first HTML document</TITLE> </HEAD> <BODY> <P>Hello world! </BODY> </HTML>
Run this program it generates:
<html><head><title>My first HTML document</title></head><body><p>Hello + world! </body><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"></html>
And this generated HTML does not pass the validate service. It complains that DOCTYPE cannot be found and is misplaced.
In reply to Re: HTML::TreeBuilder bug or feature?
by pg
in thread HTML::TreeBuilder bug or feature?
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |