Module: XML::Mapping

Defined in:
lib/xml/mapping_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#write_xml(options = { mapping: :_default }) ⇒ String

Writes this mapped object as an XML string.

Parameters:

Returns:

  • (String)

    the XML form of the object, as a compact, pretty-printed string.



18
19
20
21
22
23
24
25
# File 'lib/xml/mapping_extensions.rb', line 18

def write_xml(options = { mapping: :_default })
  xml = save_to_xml(options)
  formatter = REXML::Formatters::Pretty.new
  formatter.compact = true
  io = ::StringIO.new
  formatter.write(xml, io)
  io.string
end