Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: HTML::Tidy and mysterious HTML::Tidy::Document

by bmann (Priest)
on Jan 18, 2005 at 06:43 UTC ( #422905=note: print w/replies, xml ) Need Help??


in reply to Re^2: HTML::Tidy and mysterious HTML::Tidy::Document
in thread HTML::Tidy and mysterious HTML::Tidy::Document

Thanks for posting the code.

If you want to use the messages method, you need to parse it first, not clean it.

#!/usr/bin/perl use lib '/home/brian/lib/lib/perl/5.8.4'; use strict; use warnings; use HTML::Tidy; open M, "test.html" or die "$!"; my $html = do { local $/; <M> }; my $tidy = new HTML::Tidy; $tidy->parse( "test", $html ); for my $message ( $tidy->messages ) { print $message->as_string, $/; } __END__ output on a test file: test (1:1) Warning: missing <!DOCTYPE> declaration test (8:9) Warning: missing </form> before <option> test (6:1) Warning: <option> isn't allowed in <body> elements test (6:1) Warning: <input> isn't allowed in <body> elements test (12:33) Warning: inserting implicit <form> test (14:17) Warning: discarding unexpected </option> test (12:33) Warning: <form> lacks "action" attribute

If you want the cleaned output, it is edited in-place, ie: $tidy->clean( $html ); # $html now contains tidied output

Update: the clean method returns the clean html, as Aristotle points out below

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-05-26 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?