When def
ining tags
you are not actually building a literal list but a call to :title
with :venue_name
as its argument. Try declaring tags
as a list or a vector in the following way:
(def tags '(:title :venue_name)) ;list
(def tags [:title :venue_name]) ; vector
I suggest you clean up your code a little bit since there seems to be a number of problems with it:
- Double requirement of
clojure.data.zip.xml
. - Extra parenthesis in the definition of the function
xz
. xz
is used as both an alias for a namespace and the name of a function.- Remove the enclosing parenthesis
func
anonymous function(#(zf/xml1-> (xml-zipper tags) % zf/text))
, you are creating and calling thatfn
at the same time.
Hope it helps.
EDIT
I think I now get what you are trying to do. Here's a working version for the selector generator function: selector
. Note that the argument tag
can be either a single keyword or a sequence of keywords, in which case apply
is used when calling xml1->
.
(ns datamodel
(:require [clojure.zip :as z]
[clojure.xml :as xml]
[clojure.data.zip.xml :as zf]
[clojure.java.io :as io]))
(def data-url "http://api.eventful.com/rest/events/search?app_key=4H4Vff4PdrTGp3vV&keywords=music&location=Belgrade&date=Future")
(defn parse [url]
(z/xml-zip (xml/parse url)))
(defn selector [tag]
(if (sequential? tag)
#(apply zf/xml1-> % (concat tag [zf/text]))
#(zf/xml1-> % tag zf/text)))
(defn get-events
[xml & tags]
(let [events (zf/xml-> xml :events :event)
fs (map selector tags)]
(map (apply juxt fs) events)))
(-> data-url
parse
(get-events :title :start_time [:performers :performer :name] :stop_time)
first
prn)