Hello,
This seems like a fairly simple solution, but I keep running into
roadblocks. I''m using a small form to select an xml from the
user''s
local file system, and then parsing the information out using REXML.
The form works fine, but I can''t seem to get the body of the xml doc
opened with in the controller. I''ve included the code snippets below
for view and controller, can anyone see what i''m missing/doing wrong?
thanks,
Dave
view:
<% form_tag (:action => ''uploadXML'', :multipart =>
true) do %>
<%= file_field_tag ''file'' %></p>
<%= submit_tag "Upload" %>
<% end %>
controller:
require ''rexml/document''
include REXML
def uploadXML
xml_file = params[:file].read
elements = Document.new File.new(xml_file)
elements.root.each_element do |e|
.......
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I am not sure if you can directly read params[:file] as a file handle. I
could be wrong.
if you debug your output by typing logger.info(#{xml_file}) might provide
some hints.
On Tue, Jul 1, 2008 at 1:48 PM, loominator1970
<loominator1970-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
> Hello,
>
> This seems like a fairly simple solution, but I keep running into
> roadblocks. I''m using a small form to select an xml from the
user''s
> local file system, and then parsing the information out using REXML.
> The form works fine, but I can''t seem to get the body of the xml
doc
> opened with in the controller. I''ve included the code snippets
below
> for view and controller, can anyone see what i''m missing/doing
wrong?
>
> thanks,
> Dave
>
>
> view:
> <% form_tag (:action => ''uploadXML'', :multipart
=> true) do %>
> <%= file_field_tag ''file'' %></p>
> <%= submit_tag "Upload" %>
> <% end %>
>
> controller:
> require ''rexml/document''
> include REXML
>
> def uploadXML
> xml_file = params[:file].read
> elements = Document.new File.new(xml_file)
>
> elements.root.each_element do |e|
> .......
> end
> end
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 1 Jul 2008, at 18:48, loominator1970 wrote:> > Hello, > > This seems like a fairly simple solution, but I keep running into > roadblocks. I''m using a small form to select an xml from the user''s > local file system, and then parsing the information out using REXML. > The form works fine, but I can''t seem to get the body of the xml doc > opened with in the controller. I''ve included the code snippets below > for view and controller, can anyone see what i''m missing/doing wrong? > > thanks, > Dave > > > view: > <% form_tag (:action => ''uploadXML'', :multipart => true) do %> > <%= file_field_tag ''file'' %></p> > <%= submit_tag "Upload" %> > <% end %> > > controller: > require ''rexml/document'' > include REXML > > def uploadXML > xml_file = params[:file].read > elements = Document.new File.new(xml_file) >Just elements = Document.new params[:file] should do the trick, or elements = Document.new xml_file would probably work too. Fred> elements.root.each_element do |e| > ....... > end > end > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---