See Tutorials: perlunitut: Unicode in Perl, perluniintro/perlunitut, and utf8, binmode, Perlmonks uses the windows-1252 (similar to Latin-1) encoding, and all characters that are not in that character set are HTML-escaped - which doesn't work inside <code>...</code> tags, because everything is interpreted literally there.

So if you put all that together

#!/usr/bin/perl -- use utf8; use strict; use warnings; use XML::Twig; use Data::Dump qw/ dd /; my $rawl = q{C1000 &#12510;&#12493;&#12540;&#12472;&#12515;&#12540;&# +12477;&#12501;&#12488;&#12454;&#12455;&#12450;}; my $rawe = "C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x{30FC}\x{3 +0BD}\x{30D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}"; for my $raw ( $rawl, $rawe ){ my $t = XML::Twig->new( pretty_print => 'indented' )->xparse( "<a> +<b><q></q></b></a>" ); $t->findnodes('//q', 0 )->set_content( $raw ); dd( $raw, $t->findnodes('//q',0)->trimmed_text, $t->sprint, ); #~ $t->print( \*STDOUT ); #~ $t->print_to_file( 'outfoo.xml' ); } __END__ ( "C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x{30FC}\x{30BD}\x{30 +D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}", "C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x{30FC}\x{30BD}\x{30 +D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}", "<a>\n <b>\n <q>C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x +{30FC}\x{30BD}\x{30D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}</q>\n </b>\n< +/a>\n", ) ( "C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x{30FC}\x{30BD}\x{30 +D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}", "C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x{30FC}\x{30BD}\x{30 +D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}", "<a>\n <b>\n <q>C1000 \x{30DE}\x{30CD}\x{30FC}\x{30B8}\x{30E3}\x +{30FC}\x{30BD}\x{30D5}\x{30C8}\x{30A6}\x{30A7}\x{30A2}</q>\n </b>\n< +/a>\n", )

In reply to Re: set_content of XML::twig by Anonymous Monk
in thread set_content of XML::twig by test1

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.