开发者

REXML thinks file is a directory and won't create a REXML::Document

开发者 https://www.devze.com 2023-01-31 06:16 出处:网络
I must be missing something obvious here, but I can\'t seem to get the following code to work: xml_files_dir.each do | xml_file |

I must be missing something obvious here, but I can't seem to get the following code to work:

xml_files_dir.each do | xml_file |
  file = File.new ( xml_files_dir + "/" + xml_file )
  puts File.file? file #true. so I know the file was created and is a file
  doc = REXML::Document.new file #error
end

what I get is:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/source.rb:146:in `read': Is a directory - /Path/To/My/XML/Fil开发者_StackOverflow社区e/. (Errno::EISDIR)

Why does REXML think that my file is a directory when it appears to be a valid file?

Thanks


If you puts out xml_file in your loop, I think that you will see 'files' named . and ... You'll need some logic to make sure you dont try to process these as actual files before creating your rexml object.

I would offer a code example, but I'm not sure what type of object your xml_files_dir is. If you just throw a puts in there I think you'll see what I am talking about.

0

精彩评论

暂无评论...
验证码 换一张
取 消