Skip to content

Instantly share code, notes, and snippets.

@tstout
Created February 25, 2020 20:54
Show Gist options
  • Select an option

  • Save tstout/b19c530ddaf194326cb8312a5c6103b3 to your computer and use it in GitHub Desktop.

Select an option

Save tstout/b19c530ddaf194326cb8312a5c6103b3 to your computer and use it in GitHub Desktop.
convert clojure maps to xml #clojure
;; :require [clojure.data.xml :as xml]
(defn to-xml
"Convert an arbitrary map to xml."
[root-element x]
(xml/emit-str
(xml/element
root-element {}
(map (fn make-node [[f s]]
(cond
(map? s) (xml/element f {} (map make-node (seq s)))
(vector? s) (xml/element f {} (map make-node (partition 2 (flatten (map seq s)))))
:else (xml/element f {} s)))
(seq x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment