Welcome! Please see the About page for a little more info on how this works.

0 votes
in data.xml by
README.md illustrates writing an XML file with java.io.FileWriter.  Therefore the example works only if the Java platform's default encoding is UTF-8.  Suggestion:  The README would present a more widely usable technique by using clojure.java.io/writer, whose default encoding is UTF-8 everywhere.

Sample program using the README example:

{code:clojure}
(ns garble
  (:require [clojure.data.xml :refer [element emit]]))
(defn -main
  "Tries to write an XML file"
  []
  (let [tags (element :foo {:foo-attr "foo value"}
             (element :bar {:bar-attr "bar value"}
               (element :baz {} "The baz value")))]
  (with-open [out-file (java.io.FileWriter. "/tmp/foo.xml")]
    (emit tags out-file))))


Invocation 1 (overriding Java's default encoding because Java is inclined to use UTF-8 on my computer):

{{java -cp ... -Dfile.encoding=US-ASCII clojure.main -m garble}}

Result:

{{java.lang.Exception: Output encoding of stream (UTF-8) doesn't match declaration (ASCII)}}

Invocation 2:

{{java -cp ... -Dfile.encoding=UTF-8 clojure.main -m garble}}

Result:  successfully writes /tmp/foo.xml

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/DXML-40 (reported by alex+import)
...