Module: DbAgile::IO::XML
- Defined in:
- lib/dbagile/io/xml.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :table_element_name => "table", :row_element_name => "record"}
Class Method Summary collapse
-
.to_xml(data, columns = nil, buffer = "", options = {}) ⇒ ...
Outputs some data as a XML string.
Class Method Details
.to_xml(data, columns = nil, buffer = "", options = {}) ⇒ ...
Outputs some data as a XML string
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dbagile/io/xml.rb', line 13 def to_xml(data, columns = nil, buffer = "", = {}) require 'builder' = DEFAULT_OPTIONS.merge() ten, ren, cen = [:table_element_name], [:row_element_name], [:column_element_name] buffer << '<?xml version="1.0" encoding="UTF-8"?>' << "\n" buffer << "<#{ten}>"<< "\n" data.each{|row| buffer << " " << "<#{ren}>" << "\n" columns.each{|column| buffer << " " << "<#{column}>#{row[column].to_s.to_xs}</#{column}>" << "\n" } buffer << " " << "</#{ren}>" << "\n" } buffer << "</#{ten}>"<< "\n" buffer end |