我一直在努力解决这个问题,这可能是平庸的(或不是)。在这里 - 我想从 xml 中提取一些值。这是我的程序(应该重构,这是一个工作版本)
(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")))))
在 REPL (create-map-of-events) 中给了我一个 java.lang.RuntimeException: java.lang.NullPointerException
我对 xml1-> 做错了什么?