in reply to problem with XML::Writer, unicode and Perl 5.6.0 upgrade

Could you post some code that demonstrates the discrepancy you're describing?
  • Comment on Re: problem with XML::Writer, unicode and Perl 5.6.0 upgrade

Replies are listed 'Best First'.
Re^2: problem with XML::Writer, unicode and Perl 5.6.0 upgrade
by santellij (Novice) on Sep 28, 2004 at 21:40 UTC
    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>