          (hal/resource->representation resource :json)
          ");")))
 
-(defmethod slice-query "application/xml" [_ resource _]
-  (hal/resource->representation resource :xml))
+(defmethod slice-query "application/xml" [_ resource {:keys [request]}]
+  (let [resource (hal/xml-representation resource)
+        response (response/content-type "application/xml; charset=utf-8" {})
+        in (PipedInputStream. *stream-size*)
+        out (PipedOutputStream. in)]
+    (future
+      (with-open [out (io/writer out)]
+        (xml/emit (xml/sexp-as-element resource)
+                  out
+                  :encoding "UTF-8")))
+    (send-stream request response in *stream-size*)
+    (ring-response response)))
 
 (defmethod slice-query :default [format _ _]
   (format-not-found format))


;; Allow for encoding of UrlLike's in JSON.
(add-encoder UrlLike encode-str)

(def footer-info {:qu_version (:version project)
                  :build_number (:build-number project)

                     false)          
              (recur (drop size rows)))))))))

(defn send-stream
  [request response ^java.io.InputStream is len]
  (let [buf (char-array len)]
    (with-open [is (io/reader is)]
      (with-channel request channel
        (on-close channel #(log/info "Channel closed:" %))
        (loop [n (.read is buf)]
          (let [string (apply str (take n buf))]
            (send! channel (assoc response :body string) false)
            (when-not (= n -1)
              (recur (.read is buf)))))
        (close channel)))))

(defmethod slice-query "application/json" [_ resource {:keys [request]}]
  (let [resource (hal/json-representation resource)
        response (response/content-type "text/json; charset=utf-8" {})      
        in (PipedInputStream. *stream-size*)
        out (PipedOutputStream. in)]
    (future
      (with-open [out (io/writer out)]
        (json/generate-stream resource out)))
    (send-stream request response in *stream-size*)
    (ring-response response)))

(defmethod slice-query "text/javascript" [_ resource {:keys [callback]}]
  (let [callback (if (str/blank? callback) "callback" callback)]
