2008年8月13日星期三

Re: [PerlChina] XML中文


open(my $fh, '<', $file);
local $/ = undef;
my $string = <$fh>;
close($fh);
use Encode qw/from_to/;
from_to($string, 'gb2312', 'utf8');
use XML::Simple;
my $xs1 = new XML::Simple;
my $doc = $xs1->XMLin($string);

试试。

use Encode qw/from_to/;
from_to($string, 'gb2312', 'utf8');

试了一下XML::Parser也可以了,多谢。
对于本身就是UTF8的再from_to一次会有问题,怎么判断$string是否utf8?直接让它parse一遍,不行的话再encode?

另外,我在中文字符外面套了一层<![CDATA[     ]]>,按说DOM/Parser应该不会去管里面是什么内容?
 
--
>: ~

没有评论: