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?
In reply to emdash problems with XML::Simple by nglenn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |