abhishes has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have written Perl code to parse XML files using XML::Twig

Sometimes I get XML files with the following header

<?xml version="1.0" encoding="gbk"?>

Here my code throws an error saying

Couldn't open encmap gbk.enc: No such file or directory

How can I prevent this error? what do I need to do?

I order to solve this, I downloaded a gbk.txt from here http://www.opensource.apple.com/source/libiconv/libiconv-30/libiconv/tests/GBK.TXT

Then I installed XML-Encoding and ran the tool

make_encmap GBK GBK.TXT > GBK.encmap

but now I got the error

Minpos never set at C:\Perl\site\bin/make_encmap line 87.



I am using activestate perl 5.10.1 on Windows XP SP3

Replies are listed 'Best First'.
Re: Parsing XML with XML::Twig
by Khen1950fx (Canon) on Jul 20, 2010 at 11:07 UTC
    Unfortunately, XML::Encoding doesn't support GBK(CP936) at this time, but it does support Big5. Encode::CN is what you want to use.
      So here is what I am going to do Open the file with normal means (without try to parse XML) and replace the term gbk with Big5 and then save the file with Big5 encoding. Then I will try to parse the file and this time it should succeed as Big5 is supported. Correct?