The XML constructor can write its data to any object that supports the << operator. In your case, the String and File objects seem to be the most interesting.
Using a string would look something like this:
xml = Builder::XmlMarkup.new # Uses the default string target # TODO: Add your tags xml_data = xml.target! # Returns the implictly created string target object file = File.new("my_xml_data_file.xml", "wb") file.write(xml_data) file.close
But since the File class also supports the << operator, you can write data directly to the file:
file = File.new("my_xml_data_file.xml", "wb") xml = Builder::XmlMarkup.new target: file
See the XmlMarkup documentation for more information.
Daniel Rikowski
source share