Return to Snippet

Revision: 25329
at March 27, 2010 14:26 by iTony


Initial Code
(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)))

Initial URL
http://nakkaya.com/2010/03/27/pretty-printing-xml-with-clojure/

Initial Description

                                

Initial Title
Pretty Printer XML in clojure

Initial Tags
xml

Initial Language
Clojure