[PerlChina] XML中文
Question
wanliyou at gmail.com
Wed Aug 13 00:50:58 PDT 2008
> 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应该不会去管里面是什么内容?
--
>: ~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/china-pm/attachments/20080813/78cbbb50/attachment.html>
More information about the China-pm
mailing list