Created
February 25, 2020 20:54
-
-
Save tstout/b19c530ddaf194326cb8312a5c6103b3 to your computer and use it in GitHub Desktop.
convert clojure maps to xml #clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; :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