On Windows,
use strict; use warnings; use XML::DOM; my $xml = <<"__EOI__"; <?xml version="1.0" encoding="UTF-8"?> <TEST> \xC3\xA9 </TEST> __EOI__ my $parser = new XML::DOM::Parser; my $doc = $parser->parse($xml); $doc->printToFile("test.xml");
>perl a.pl >perl -e"$/=\16; while (<>) { my $s=uc unpack 'H*', $_; $s=~s/..\K/ /g +; print qq{$s\n}; }" test.xml 3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 20 65 6E 63 6F 64 69 6E 67 3D 22 55 54 46 2D 38 22 3F 3E 0A 3C 54 45 53 54 3E 20 E9 20 3C 2F 54 45 53 54 3E 0A

As previously shown, XML::DOM doesn't encode for you (as it should). So let's try with the previously mentioned fix:

use strict; use warnings; use XML::DOM; my $xml = <<"__EOI__"; <?xml version="1.0" encoding="UTF-8"?> <TEST> \xC3\xA9 </TEST> __EOI__ my $parser = new XML::DOM::Parser; my $doc = $parser->parse($xml); open my $fh, ">:utf8", "test.xml" or die $!; $doc->printToFileHandle($fh);
>perl a.pl >perl -e"$/=\16; while (<>) { my $s=uc unpack 'H*', $_; $s=~s/..\K/ /g +; print qq{$s\n}; }" test.xml 3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 20 65 6E 63 6F 64 69 6E 67 3D 22 55 54 46 2D 38 22 3F 3E 0A 3C 54 45 53 54 3E 20 C3 A9 20 3C 2F 54 45 53 54 3E 0A

Perl did its thing correctly, so you have a problem with your editor. There are some solutions:

You might want to check (using the above command) to make sure your input contains what you think it contains.


In reply to Re: XML:: DOM and Accented Characters by ikegami
in thread XML:: DOM and Accented Characters by freeflyer

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.