Monks:

I'm using HTML::Table to build—you guessed it—an HTML table, and then incorporate that into XML::Twig.

As soon as I put these two together I see "Wide character in print..." and XML::Twig (apparently) no longer honors output_text_filter.

The code follows, as well as the results explained in the code:
use warnings; use strict; use Encode; use XML::Twig; use HTML::Table; undef $/; my $html = <DATA>; my $twig = XML::Twig->new( input_filter => sub { my $txt = shift; return decode('Windows-1252', $txt); }, output_text_filter => 'safe_hex', pretty_print => 'indented', twig_print_outside_roots => 1, twig_roots => { 'h1' => sub { ### If 1: ### - "Wide character in print..." ### - TM is *not* converted to &#x2122; by output_text_fi +lter ### If 0: ### - No character complaints ### - TM *is* converted if (1) { my $new_elt = XML::Twig::Elt->new('div'); my $table = HTML::Table->new([[1,2]]); $new_elt->set_inner_html($table->getTable()); $new_elt->paste(before => $_); } $_->flush(); } }, ); $twig->parse_html($html); __DATA__ <html> <body> <h1>Such and Such™</h1> </body> </html>
The result with 1:
<?xml version="1.0" encoding="iso-8859-1"?><html><head></head><body> <div> <table> <tbody> <tr> <td>1</td> <td>2</td> </tr> </tbody> </table> </div> Wide character in print at /usr/local2/lib/perl_aps/XML/Twig.pm line 7 +662, <DATA> chunk 1. <h1>Such and Suchâ¢</h1> </body> </html>
The result with 0:
<?xml version="1.0" encoding="iso-8859-1"?><html><head></head><body> <h1>Such and Such&#x2122;</h1> </body> </html>
Q: Why don't I/How can I get:
<?xml version="1.0" encoding="iso-8859-1"?><html><head></head><body> <div> <table> <tbody> <tr> <td>1</td> <td>2</td> </tr> </tbody> </table> </div> <h1>Such and Such&#x2122;</h1> </body> </html>
Thanks, this had been puzzling me all afternoon!

In reply to XML::Twig, HTML::Table, and wide characters by eff_i_g

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.