in Education by
I'm trying to import an XML file via a web page in a Ruby on Rails application, the code ruby view code is as follows (I've removed HTML layout tags to make reading the code easier) <% form_for( :fmfile, :url => '/fmfiles', :html => { :method => :post, :name => 'Form_Import_DDR', :enctype => 'multipart/form-data' } ) do |f| %> <%= f.file_field :document, :accept => 'text/xml', :name => 'fmfile_document' %> <%= submit_tag 'Import DDR' %> <% end %> Results in the following HTML form
The Form_Import_DDR method in the 'fmfiles_controller' is the code that does the hard work of reading the XML document in using REXML. The code is as follows @fmfile = Fmfile.new @fmfile.user_id = current_user.id @fmfile.file_group_id = 1 @fmfile.name = params[:fmfile_document].original_filename respond_to do |format| if @fmfile.save require 'rexml/document' doc = REXML::Document.new(params[:fmfile_document].read) doc.root.elements['File'].elements['BaseTableCatalog'].each_element('BaseTable') do |n| @base_table = BaseTable.new @base_table.base_table_create(@fmfile.user_id, @fmfile.id, n) end And it carries on reading all the different XML elements in. I'm using Rails 2.1.0 and Mongrel 1.1.5 in Development environment on Mac OS X 10.5.4, site DB and browser on same machine. My question is this. This whole process works fine when reading an XML document with character encoding UTF-8 but fails when the XML file is UTF-16, does anyone know why this is happening and how it can be stopped? I have included the error output from the debugger console below, it takes about 5 minutes to get this output and the browser times out before the following output with the 'Failed to open page' Processing FmfilesController#create (for 127.0.0.1 at 2008-09-15 16:50:56) [POST] Session ID: BAh7CDoMdXNlcl9pZGkGOgxjc3JmX2lkIiVmM2I3YWU2YWI4ODU2NjI0NDM2 NTFmMDE1OGY1OWQxNSIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxh c2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--dd9f588a68ed628ab398dd1a967eedcd09e505e0 Parameters: {"commit"=>"Import DDR", "authenticity_token"=>"3da97372885564a4587774e7e31aaf77119aec62", "action"=>"create", "fmfile_document"=>#, "controller"=>"fmfiles"} [4;36;1mUser Load (0.000350)[0m [0;1mSELECT * FROM "users" WHERE (id = 1) LIMIT 1[0m [4;35;1mFmfile Create (0.000483)[0m [0mINSERT INTO "fmfiles" ("name", "file_group_id", "updated_at", "report_created_at", "report_link", "report_version", "option_on_open_account_name", "user_id", "option_default_custom_menu_set", "option_on_close_script", "path", "report_type", "option_on_open_layout", "option_on_open_script", "created_at") VALUES('TheTest_fp7 2.xml', 1, '2008-09-15 15:50:56', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, '2008-09-15 15:50:56')[0m REXML::ParseException (# /Library/Ruby/Site/1.8/rexml/encodings/ICONV.rb:7:in `conv' /Library/Ruby/Site/1.8/rexml/encodings/ICONV.rb:7:in `decode' /Library/Ruby/Site/1.8/rexml/source.rb:50:in `encoding=' /Library/Ruby/Site/1.8/rexml/parsers/baseparser.rb:210:in `pull' /Library/Ruby/Site/1.8/rexml/parsers/treeparser.rb:21:in `parse' /Library/Ruby/Site/1.8/rexml/document.rb:190:in `build' /Library/Ruby/Site/1.8/rexml/document.rb:45:in `initialize' JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Rather than a rails/mongrel problem, it sounds more likely that there's an issue either with your XML file or with the way REXML handles it. You can check this by writing a short script to read your XML file directly (rather than within a request) and seeing if it still fails. Assuming it does, there are a couple of things I'd look at. First, I'd check you are running the latest version of REXML. A couple of years ago there was a bug (http://www.germane-software.com/projects/rexml/ticket/63) in its UTF-16 handling. The second thing I'd check is if you're issue is similar to this: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ba7b0585c7a6330d. If so you can try the workaround in that thread. If none of the above helps, then please reply with more information, such as the exception you are getting when you try and read the file.

Related questions

0 votes
    I moved a web app that was using 1.8.7 to 1.9.2 and now I keep getting incompatible character ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to access my .xml file in the ClientBin with no success. code: WebClient xmlClient = ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I have two computers. Both running WinXP SP2 (I don't really know ho similar they are beyond that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    I have two computers. Both running WinXP SP2 (I don't really know ho similar they are beyond that ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    So I have a file not found problem. I have an engine that works in development mode in the engines test/ ... :Rails::Engine isolate_namespace CcsCms::PublicTheme paths["app/views"]...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am developing an application with Rails 3.0 and Backbone and I tried asset precompilation (rake assets: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I want to encode an image into a string using the base64 module. I've ran into a problem though. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Is there any way to change the default datatype when importing an Excel file into Access? (I'm using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Is there any way to change the default datatype when importing an Excel file into Access? (I'm using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Is there any way to change the default datatype when importing an Excel file into Access? (I'm using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    Is there any way to change the default datatype when importing an Excel file into Access? (I'm using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    What is the default value used by sqoop when it encounters a missing value while importing form CSV file. A - NULL B - null C - space character D - No values...
asked Jan 13, 2021 in Technology by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
...