Clojure: extracting data from xml using clj-xpath

I am using clj-xpath library to fetch data from xml that comes from API. As an output, I expect the tags and their content to be displayed. I have a function that works, here's a code snippet:

(use 'clj-xpath.core)

(def data-url
 str "http://api.eventful.com/rest/events/search?" "app_key=4H4Vff4PdrTGp3vV&" "keywords=music&location=New+York&date=Future")

(defn create-keys [tags]
(into [] (map keyword tags)))

(defn tag-fn [tag] (partial $x:text tag))

(defn func-contents [tags root-tag data-url] 
 (map (apply juxt (map tag-fn tags)) (take 2 ($x root-tag (xml->doc (slurp data-url ))))))

(defn create-contents [tags root-tag data-url] 
(map #(zipmap (create-keys tags) %) (func-contents tags root-tag data-url)))

      

However, when I call create-contents it doesn't add keys

(func-contents ["url" "title"] "//event" data-url)

(["http://newyorkcity.eventful.com/events/chamber-music-society-lincoln-center-mixed-wind-/E0-001- 067617553-1?utm_source=apis&utm_medium=apim&utm_campaign=apic" "Chamber Music Society of Lincoln Center - MIxed Winds"] ["http://newyorkcity.eventful.com/events/evil-dead-musical-/E0-001-070989019-4?utm_source=apis&utm_medium=apim&utm_campaign=apic" "Evil Dead The Musical"])

      

And when I just evaluate his body, he gives the expected result.

(map #(zipmap (create-keys ["url" "title"]) %) (func-contents ["url" "title"] "//event" data-url))
({:title "Chamber Music Society of Lincoln Center - MIxed Winds", :url    "http://newyorkcity.eventful.com/events/chamber-music-society-lincoln-center-mixed-wind-/E0-001-067617553-1?utm_source=apis&utm_medium=apim&utm_campaign=apic"} {:title "Evil Dead The Musical", :url "http://newyorkcity.eventful.com/events/evil-dead-musical-/E0-001-070989019-4?utm_source=apis&utm_medium=apim&utm_campaign=apic"})

      

Any ideas? The problem is probably with the create-keys function, but I need it because I want common functionality for any set of tags.

+3


source to share





All Articles