How do I create a XML file from a form in ruby on rails. The form elements should be converted into xml file and stored in my system at a specific location. I am a newbie. so please help me out with some codes.
Thanks in advance.
How do I create a XML file from a form in ruby on rails. The form elements should be converted into xml file and stored in my system at a specific location. I am a newbie. so please help me out with some codes.
Thanks in advance.
woohoo, vague questions :)
Try the newbie approach to xml
xml = "<outerNode><innerNode>#{params[:someparam]}</innerNode></outerNode>"
check out FileUtils for how to save strings to files
i know how to use file utils to save the file.. the prob is how do i generate the and the from the form elements? shoud i use the Builder class?
You could do something like this:
#!/usr/bin/ruby
require 'builder'
favorites = {
'candy' => 'Neccos', 'novel' => 'Empire of the Sun', 'holiday' => 'Easter'
}
xml = Builder::XmlMarkup.new( :target => $stdout, :indent => 2 )
xml.instruct! :xml, :version => "1.1", :encoding => "US-ASCII"
xml.favorites do
favorites.each do | name, choice |
xml.favorite( choice, :item => name )
end
end