Skip to content

Instantly share code, notes, and snippets.

@zaiste
Created February 5, 2017 22:36
Show Gist options
  • Select an option

  • Save zaiste/1cc35b6541253452b81962fc1553e02f to your computer and use it in GitHub Desktop.

Select an option

Save zaiste/1cc35b6541253452b81962fc1553e02f to your computer and use it in GitHub Desktop.
Create XML in Clojure
(ns clojure-xml-example.core
(:require [clojure.data.xml :as xml])
(:gen-class))
(def bookshelf
(xml/element :books {}
(xml/element :book {:author "Stuart Halloway"}
"Programming Clojure")
(xml/element :book {:author "Christian Queinnec"}
"Lisp in Small Pieces")
(xml/element :book {:author "Harold Abelson, Gerald Jay Sussman"}
"Structure and Interpretation of Computer Programs")))
(defn -main
[]
;; work around dangerous default behaviour in Clojure
(alter-var-root #'*read-eval* (constantly false))
(println (xml/emit-str bookshelf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment