Created
October 3, 2011 22:34
-
-
Save jdoig/1260444 to your computer and use it in GitHub Desktop.
XML to Json with some transformation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns xml_test.core | |
(:require [clojure.zip :as zip] | |
[clojure.xml :as xml] | |
[clj-json.core :as json]) | |
(:use clojure.contrib.zip-filter.xml)) | |
(defn -main [& args] | |
(let [paintings (zip/xml-zip (xml/parse "paintings.xml"))] | |
(->> (xml-> paintings :painting) | |
(map (fn [painting] { :name (first (xml-> painting :img (attr :alt))) | |
:caption (first (xml-> painting :caption text))})) | |
json/generate-string | |
(spit "paintings.json")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice, but what does it /mean/ ;-P