With HTML::Tiny? HTML::Tiny doesn't seem like an appropriate choice. To begin with, it has no support for parsing HTML!

Here's an example using HTML::HTML5::Parser and HTML::HTML5::Writer; two modules that I wrote, which are available on the CPAN.

#!/usr/bin/env perl use strict; use warnings; use HTML::HTML5::Parser; use HTML::HTML5::Writer qw(DOCTYPE_XHTML1); my $parser = 'HTML::HTML5::Parser'->new; my $writer = 'HTML::HTML5::Writer'->new(markup => 'xhtml', doctype => +DOCTYPE_XHTML1); print $writer->document( $parser->load_html(IO => \*DATA) ); __DATA__ <!doctype html> <HTML LANG="en"> <title>Some HTML</TITLE> <P>Here is some HTML</body>

Adding XML::LibXML::PrettyPrint into the mix allows you to tidy up the XHTML output, nicely indenting the tags:

#!/usr/bin/env perl use strict; use warnings; use HTML::HTML5::Parser; use HTML::HTML5::Writer qw(DOCTYPE_XHTML1); use XML::LibXML::PrettyPrint; my $parser = 'HTML::HTML5::Parser'->new; my $writer = 'HTML::HTML5::Writer'->new(markup => 'xhtml', doctype => +DOCTYPE_XHTML1); my $pp = 'XML::LibXML::PrettyPrint'->new_for_html; print $writer->document( $pp->pretty_print( $parser->load_html(IO => \*DATA), ), ); __DATA__ <!doctype html> <HTML LANG="en"> <title>Some HTML</TITLE> <P>Here is some HTML</body>

Sample output:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html lang="en" xmlns="http:// +www.w3.org/1999/xhtml"> <head> <title>Some HTML</title> </head> <body> <p>Here is some HTML</p> </body> </html>

(I really need to look at adding a line break after the doctype.)

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re: convert whole html-files to xml by tobyink
in thread convert whole html-files to xml by dschinn1001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.