Venerable monks!

I have collection of spanish-language html-files that I want to convert into a plucker document.

But before I can do that I need to get rid of some crap that the files contain, so I parse them, extract the things I want and create a new html-file containing just the extracted bits.

The files I start with are utf8-encoded and claim (in the DOCTYPE) to be xhtml, but they don't validate (missing closing tags - oh well) so I use HMTL::TreeBuilder::XPath for parsing.

Now the thing is that the source-documents do not use any html-entities but contain the spanish special characters as (2 bytes) utf-characters. And this is where I have a problem.

Here my code (which works apart from the problem below):

use strict; use HTML::TreeBuilder::XPath; my $tree = HTML::TreeBuilder::XPath->new; $tree->parse_file("in.html"); my ($tit) = $tree->findnodes(q{/html//h1[@class='title']}); my ($sub) = $tree->findnodes(q{/html//div[@class='submitted']}); my ($aut) = $tree->findnodes(q{/html//div[@class='autor']}); my ($art) = $tree->findnodes(q{/html//div[@class='content clear-block' +]}); my ($nav) = $tree->findnodes(q{/html//div[@class='book-navigation']}); $nav->detach; my (@childs, undef, undef) = $art->content_list; open my $fh, ">", "out.html" or die $!; print $fh "<html><body>" . join("\n", map { $_->as_HTML } ($tit, $sub, $aut, $art) +) . "</body></html>";
What happens now is that e.g. the spanish character ú that is encoded as hex c3ba in the source document gets transformed into &Atilde;&ordm; (i.e. ú) in the output - and that is wrong...

Does someone have an idea on how to fix this?

Many thanks!


In reply to transforming html by morgon

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.