module DataMapper::Serializer::ValidationErrors::ToXml

Public Instance Methods

to_xml(opts = {}) click to toggle source
# File lib/dm-serializer/to_xml.rb, line 67
def to_xml(opts = {})
  to_xml_document(opts).to_s
end
to_xml_document(opts = {}) click to toggle source
# File lib/dm-serializer/to_xml.rb, line 71
def to_xml_document(opts = {})
  xml = DataMapper::Serializer::XML.serializer
  doc = xml.new_document
  root = xml.root_node(doc, "errors", {'type' => 'hash'})

  errors.each do |key, value|
    property = xml.add_node(root, key.to_s, nil, {'type' => 'array'})
    property.attributes["type"] = 'array'

    value.each do |error|
      xml.add_node(property, "error", error)
    end
  end

  doc
end