in reply to convert whole html-files to xml

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

Replies are listed 'Best First'.
Re^2: convert whole html-files to xml
by dschinn1001 (Initiate) on Sep 15, 2013 at 09:23 UTC

    have updated my q - but not seen your answer.
    sometimes am blind ...

    Your answer is hitting ! - will test it today ...
    thxalotz

      "have updated my q"

      Your question seems to make the assumption that HTML::Tiny works identically to XML::Simple but processes HTML instead of XML. It does not. The two modules are completely unrelated. Applying knowledge from an XML::Simple article to HTML::Tiny will not do what you want.

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

        The main reason, why I was putting this question above is,
        that I planned to create xml-files out of html-files,
        then later to create files in c/c++ out of xml-files.
        thought simply it would becoming then a faster homepage,
        when it is later compiled in C or C++. - but now ... html is
        only script-language and C is not script-language - so
        this idea would not work then ? - but main thing is first to create xml-files or files in html5 are okay too.
        How look next steps to do ?

        here is a sample in html - name of file is test001.html: (was not possible to post example here - the code is got
        swallowed somehow - would have to mask the whole code ?)

          A reply falls below the community's threshold of quality. You may see it by logging in.