Pretty Printer XML in clojure


/ Published in: Clojure
Save to your folder(s)



Copy this code and paste it in your HTML
  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)))

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.