Posted By

iTony on 03/27/10


Tagged

xml clojure


Versions (?)

Pretty Printer XML in clojure


 / Published in: Clojure
 

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

  1. (defn ppxml [xml]
  2. (let [in (javax.xml.transform.stream.StreamSource.
  3. (java.io.StringReader. xml))
  4. writer (java.io.StringWriter.)
  5. out (javax.xml.transform.stream.StreamResult. writer)
  6. transformer (.newTransformer
  7. (javax.xml.transform.TransformerFactory/newInstance))]
  8. (.setOutputProperty transformer
  9. javax.xml.transform.OutputKeys/INDENT "yes")
  10. (.setOutputProperty transformer
  11. "{http://xml.apache.org/xslt}indent-amount" "2")
  12. (.setOutputProperty transformer
  13. javax.xml.transform.OutputKeys/METHOD "xml")
  14. (.transform transformer in out)
  15. (-> out .getWriter .toString)))

Report this snippet  

You need to login to post a comment.