def extract_and_serialize_value(builder, obj, field, type)
      v = if obj.is_a?(Hash)
        obj[field] or obj[field.to_sym] or obj[field.to_s.underscore] or obj[field.to_s.underscore.to_sym]
      elsif obj.respond_to?(field)
        obj.send(field)
      elsif obj.respond_to?(field.underscore)
        obj.send(field.underscore)
      else
        raise "Could not extract #{field.inspect} from object: #{obj.inspect}"
      end

      if v.nil?
        builder.tag! field.camelize_if_symbol, 'xsi:nil' => 'true'
      else
        builder.tag! field.camelize_if_symbol, v
      end
    end
def extract_and_serialize_value(builder, obj, field, type)
      v = if obj.is_a?(Hash)
        obj[field] or obj[field.to_sym] or obj[field.to_s.underscore] or obj[field.to_s.underscore.to_sym]
      elsif obj.respond_to?(field)
        obj.send(field)
      elsif obj.respond_to?(field.underscore)
        obj.send(field.underscore)
      else
        raise "Could not extract #{field.inspect} from object: #{obj.inspect}"
      end

      if v.nil?
        builder.tag! field.camelize_if_symbol, 'xsi:nil' => 'true'
      else
        builder.tag! field.camelize_if_symbol, v
      end
    end
Extracts a field from an object, casts it to the appropriate type, and serializes as XML.

 @param builder [Builder::XmlMarkup] The XML builder.
 @param obj [Hash,Object] The resulting object.
 @param field [Symbol,String] The field to extract.
 @param type [Class] The type to convert.