Question

I've been banging my head on this, it is probably something banal (or not). Here it is - I want to pull some values from xml. Here is my program (it should be refactored, this is a working version)

    (ns datamodel
    (:import (java.io ByteArrayInputStream))
    (:use 
    [net.cgrand.enlive-html :as en-html ])
    (:require
[clojure.zip :as z] 
[clojure.data.zip.xml :only (attr text xml->)]
[clojure.xml :as xml ]
[clojure.contrib.zip-filter.xml :as zf]
))
 (def data-url "http://api.eventful.com/rest/events/search?app_key=4H4Vff4PdrTGp3vV&keywords=music&location=Belgrade&date=Future")

 (defstruct event :event-name :performers :start-time :stop-time)

(defn get-events [xz] 
(map (juxt #(zf/xml1-> % (:title text)) 
    #(zf/xml1-> % (:performers :performer :name text)) 
    #(zf/xml1-> % (:start_time text)) 
     #(zf/xml1-> % (:stop_time text)))
 (zf/xml-> xz  :events :event)))

 (defn create-map-of-events []
(map #(apply struct event %) (get-events (z/xml-zip (xml/parse "http://api.eventful.com/rest/events/search? app_key=4H4Vff4PdrTGp3vV&keywords=music&location=Belgrade&date=Future")))))

in REPL (create-map-of-events) is giving me a java.lang.RuntimeException: java.lang.NullPointerException

What am I doing wrong with xml1->?

Was it helpful?

Solution

The problem was here

    (defn get-events
    [xz] 
   (map (juxt 
    #(zf/xml1-> % :title zf/text) 
    #(zf/xml1-> % :performers :performer :name zf/text) 
    #(zf/xml1-> % :start_time zf/text) 
     #(zf/xml1-> % :stop_time zf/text))
    (zf/xml-> xz  :events :event)))

I've put :title zf/text in parenthesis, and that was a mistake. Now it works just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top