问题
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