/ Published in: Clojure
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(defn ppxml [xml] (let [in (javax.xml.transform.stream.StreamSource. (java.io.StringReader. xml)) writer (java.io.StringWriter.) out (javax.xml.transform.stream.StreamResult. writer) transformer (.newTransformer (javax.xml.transform.TransformerFactory/newInstance))] (.setOutputProperty transformer javax.xml.transform.OutputKeys/INDENT "yes") (.setOutputProperty transformer "{http://xml.apache.org/xslt}indent-amount" "2") (.setOutputProperty transformer javax.xml.transform.OutputKeys/METHOD "xml") (.transform transformer in out) (-> out .getWriter .toString)))
URL: http://nakkaya.com/2010/03/27/pretty-printing-xml-with-clojure/