# File lib/dm-serializer/to_xml.rb, line 22
    def to_xml_document(opts={}, doc = nil)
      xml = XMLSerializers::SERIALIZER
      doc ||= xml.new_document
      default_xml_element_name = lambda { Extlib::Inflection.underscore(model.name).tr("/", "-") }
      root = xml.root_node(doc, opts[:element_name] || default_xml_element_name[])
      properties_to_serialize(opts).each do |property|
        value = send(property.name)
        attrs = (property.type == String) ? {} : {'type' => property.type.to_s.downcase}
        xml.add_node(root, property.name.to_s, value, attrs)
      end

      (opts[:methods] || []).each do |meth|
        if self.respond_to?(meth)
          xml_name = meth.to_s.gsub(/[^a-z0-9_]/, '')
          value = send(meth)
          unless value.nil?
            if value.respond_to?(:to_xml_document)
              xml.add_xml(root, value.send(:to_xml_document))
            else
              xml.add_node(root, xml_name, value.to_s)
            end
          end
        end
      end
      doc
    end