From: rook401@... Date: 2007-11-12T10:42:35+09:00 Subject: [ruby-list:44207] REXML で UTF16 のファイルが読み込めない --0-1872641947-1194831751=:67873 Content-Type: text/plain; charset=iso-2022-jp REXML で UTF16 のファイルを読み込もうとするとエラーになります。 上手な対処法があるのでしょうか? - test.rb ------------------------- require 'rexml/document' doc = nil File.open('u16.xml') {|f| doc = REXML::Document.new f.read } ----------------------------------- >ruby -vr rexml/rexml -e "puts REXML::Version" ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] 3.1.7.1 >ruby test.rb C:/Ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:90:in `parse': # x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 1 6 " ? > C:/Ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:346:in `pull' C:/Ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:21:in `parse' C:/Ruby/lib/ruby/1.8/rexml/document.rb:204:in `build' C:/Ruby/lib/ruby/1.8/rexml/document.rb:42:in `initialize' --------------------------------- New Design Yahoo! JAPAN 2008/01/01 --0-1872641947-1194831751=:67873 Content-Type: text/html; charset=iso-2022-jp REXML で UTF16 のファイルを読み込もうとするとエラーになります。
上手な対処法があるのでしょうか?

- test.rb -------------------------
require 'rexml/document'

doc = nil
File.open('u16.xml') {|f|
  doc = REXML::Document.new f.read
}
-----------------------------------

>ruby -vr rexml/rexml -e "puts REXML::Version"
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
3.1.7.1

>ruby test.rb
C:/Ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:90:in `parse': #<REXML::ParseException: malformed XML: missing tag start (REXML::ParseException)
Line:
Position:
Last 80 unconsumed characters:
 > x m l  v e r s i o n = " 1 . 0 "  e n c o d i n g  = " U T F - 1 6 " ? >
C:/Ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:346:in `pull'
C:/Ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:21:in `parse'
C:/Ruby/lib/ruby/1.8/rexml/document.rb:204:in `build'
C:/Ruby/lib/ruby/1.8/rexml/document.rb:42:in `initialize'

 


New Design Yahoo! JAPAN 2008/01/01
--0-1872641947-1194831751=:67873--