nglenn has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to parse an XML file with XML simple. The XML file has some attributes that include emdashes. Here is the xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <table id="{4fa6cd7a-f7b6-416d-8f59-3acc0eab9bdb}"> <level type="b"> <map abrv="JS—M"/> <map abrv="JS—K"/> </level> </ettx>
Here is the code to show the error:
#!/usr/bin/perl -l use strict; use warnings; use XML::Simple; use Data::Dumper; my $xml = XML::Simple->new(); my $fileName = 'C:\Users\nate\Desktop\testXML.txt'; my $tree = { table => {} }; $tree->{table} = $xml->XMLin($fileName, ForceArray => ['map'], KeyAttr => [] ) ->{table}; print Dumper($tree->{table});
Just change the file path to test it. The error produced when I run it is: Cannot decode string with wide characters at C:/Perl/lib/Encode.pm line 174.
What really annoys me is that there is a much bigger file that has the emdash in some attributes and it parses fine until I remove a certain number of lines, after which it produces the above error. Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: emdash problems with XML::Simple
by ikegami (Patriarch) on Aug 26, 2010 at 19:25 UTC | |
by nglenn (Beadle) on Aug 26, 2010 at 19:58 UTC | |
by ikegami (Patriarch) on Aug 26, 2010 at 21:45 UTC | |
by nglenn (Beadle) on Aug 28, 2010 at 03:14 UTC | |
by ikegami (Patriarch) on Aug 28, 2010 at 03:47 UTC | |
|
Re: emdash problems with XML::Simple
by psini (Deacon) on Aug 26, 2010 at 18:53 UTC | |
by nglenn (Beadle) on Aug 26, 2010 at 19:51 UTC |