简体   繁体   中英

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

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/File/. (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM