It's nothing fancy but here's a test script:
#!/usr/local/bin/perl use bytes; use strict; use XML::Parser; use XML::Writer; use IO::File; my $out_xml_file = "out.xml"; my $print_out_xml_file = "print_out.xml"; my $xmlFile = "in.xml"; my $parser = new XML::Parser(); $parser->setHandlers( Start => \&StartHandler, End => \&EndHandler, Comment => \&CommentHandler, Char => \&CharHandler, Default => \&DefaultHandler, ); my $print_out_file = new IO::File(">$print_out_xml_file"); my $out_file = new IO::File(">$out_xml_file"); binmode($out_file, ":encoding(utf-8)"); my $write = new XML::Writer(OUTPUT => $out_file, DATA_INDENT => 2); print $print_out_file qq(<?xml version="1.0" encoding="UTF-8"?>); print $print_out_file "<root_out>\n"; $write->xmlDecl("UTF-8"); $write->startTag("root_out"); $parser->parsefile($xmlFile); print $print_out_file "</root_out>"; $write->endTag("root_out"); $write->end(); $out_file->close(); $print_out_file->close(); ## ---------------------## ## Handlers for XML Parser ## sub StartHandler { my ($p, $el) = @_; print "start: $el\n"; print $print_out_file "<$el>\n"; $write->startTag($el); } sub EndHandler { my ($p,$el) = @_; print "end: $el\n"; print $print_out_file "</$el>\n"; $write->endTag($el); } sub CharHandler { my ($p,$chr) = @_; print "Char: $chr\n"; print $print_out_file "$chr"; $write->characters($chr); } sub CommentHandler { my ($p,$com) = @_; print "Comment found: $com\n"; } sub DefaultHandler { my($p,$str) = @_; print "Default found: $str\n"; }

...and the "in.xml" file (I'm not sure the utf-8 in the test1 element will be correct after copy-n-paste):
<?xml version="1.0" encoding="UTF-8"?> <root> <test1>—</test1> <test2>&#151;</test2> </root>

In reply to Re^2: problem with XML::Writer, unicode and Perl 5.6.0 upgrade by santellij
in thread problem with XML::Writer, unicode and Perl 5.6.0 upgrade by santellij

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.