REXML::Document.new can we give encode parameters on this line?

邮差的信 提交于 2019-12-02 16:36:34

问题


doc = REXML::Document.new file My code is failing at this point whenever my xml file contains some special characters other than UTF-8 .

REXML::ParseException (#<REXML::ParseException: #<ArgumentError: invalid byte sequence in UTF-8>

回答1:


You can call something like this

REXML::Document.new(file.force_encoding("FILE_ENCODING").encode("UTF-8"))

FILE_ENCODING is the encoding of your file variable.



来源:https://stackoverflow.com/questions/17194393/rexmldocument-new-can-we-give-encode-parameters-on-this-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!