nglenn has asked for the wisdom of the Perl Monks concerning the following question:
I am using XML::Simple to parse some utf8 xml files. However, utf8 files with BOM cause it to crash and burn with the following error:
Wide character in subroutine entry at C:/Perl/lib/Encode.pm line 174.The offending code is:
use XML::Simple; local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; $xml->XMLin($file,ForceArray => ['map'], KeyAttr =>{},);
The error does NOT occur with utf8 files that have no BOM. Seems bazaar, and I have no idea what to do. Any suggestions?
Update:
It has to be the way I'm using it. Here's more context for the code I posted earlier:
In ETTX.pm:
package ETTX; use strict; use XML::Simple; local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; use XML::SemanticDiff; sub new(){#scalar file name my $class = shift; my $self = { ettxFile => '', ettx => {}, }; bless $self, $class; load($self,shift) if @_ ==1; return $self; }; sub load(){#scalar file name my ($self, $ettxFile) = @_; print "loading $ettxFile"; open(my $fh, '<', $ettxFile); binmode($fh); my $xml = XML::Simple->new(); $self->{ettx} = $xml->XMLin($fh, ForceArray => ['map'], KeyAttr => {}, ) ->{table}; $self->{ettxFile} = $ettxFile; # print Dumper($self); 1; }
The code above was changed to to use the binmode() thing, but still fails just the same.
Called like so:
And here's a sample xml file:use lib 'C:\Texts\Programs'; #wherever ETTX.pm is use ETTX; my $ettxFile = 'someXMLfile.ettx'; my $ettx->load($ettxFile);
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <ettx ver="2"> <table id="{4fa6cd7a-f7b6-416d-8f59-3acc0eab9bdb}" name="TestFile"> <level type="V"> <map sync="Title" src="someText"/> <map sync="Title Page" src="someText"/> </level> </table> </ettx>
|
|---|