Q:

Ruby create XML file

I need to create xml file for upload, found how to create body, but that code return structure of file and not file, could you please help me? Should I just push that structure to new file or there is more easy way to do it?
Many thanks!
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
  xml.root {
    xml.products {
      xml.widget {
        xml.id_ "10"
        xml.name "Awesome widget"
      }
    }
  }.to_xml
end

A:

Just use IO.write to get your.xml
content = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
  xml.root {
    xml.products {
      xml.widget {
        xml.id_ "10"
        xml.name "Awesome widget"
      }
    }
  }
end

File.write("your.xml", content.to_xml)

