def to_xml(options = {})
      doc = Nokogiri::XML::Document.new
      root = doc.create_element(tag_name)
      self.class.keys.each do |name|
        value = read_attribute(name)
        next if value.blank?
        root[name.to_s.camelize] = value
      end
      self.class.elements.each do |name, field|
        next if options[:only] && !options[:only].include?(name)
        next if field.options[:readonly]
        value = read_attribute(name)
        next if field.type.is_a?(Array) && value.blank?
        next if new_record? && field.type == Identifier
        next if new_record? && value.blank?
        if name == :text
          root << value.to_s
        else
          root << field.to_xml(value)
        end
      end
      root
    end
def to_xml(options = {})
      doc = Nokogiri::XML::Document.new
      root = doc.create_element(tag_name)
      self.class.keys.each do |name|
        value = read_attribute(name)
        next if value.blank?
        root[name.to_s.camelize] = value
      end
      self.class.elements.each do |name, field|
        next if options[:only] && !options[:only].include?(name)
        next if field.options[:readonly]
        value = read_attribute(name)
        next if field.type.is_a?(Array) && value.blank?
        next if new_record? && field.type == Identifier
        next if new_record? && value.blank?
        if name == :text
          root << value.to_s
        else
          root << field.to_xml(value)
        end
      end
      root
    end
Builds XML from elements and attributes