<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">open(my $fh, '<', $file);<br>
local $/ = undef;<br>
my $string = <$fh>;<br>
close($fh);<br>
use Encode qw/from_to/;<br>
from_to($string, 'gb2312', 'utf8');<br>
<div class="Ih2E3d">use XML::Simple;<br>
my $xs1 = new XML::Simple;<br>
</div>my $doc = $xs1->XMLin($string);<br>
<br>
试试。<br>
<br></blockquote><div>use Encode qw/from_to/;<br>
from_to($string, 'gb2312', 'utf8');<br><br>试了一下XML::Parser也可以了,多谢。<br>对于本身就是UTF8的再from_to一次会有问题,怎么判断$string是否utf8?直接让它parse一遍,不行的话再encode?<br><br>另外,我在中文字符外面套了一层<![CDATA[ ]]>,按说DOM/Parser应该不会去管里面是什么内容?<br>
</div></div>-- <br>>: ~<br>
</div>