returning multiple values using clojure xml zipper

北城余情 提交于 2019-12-05 15:52:29

Depending on the clojure version you use, you might find the juxt function useful. Your posted code (only relevant parts):

(defn extract-data
  [xml] 
  (let [...]
    (map (juxt getASIN (comp getTitle getAttributes) (comp getAuthor getAttributes)) items))))

I'm sure there is a nicer way, but this does the job:

(letfn [(get-tag [tag coll] (:content (first (filter #(= tag (:tag %)) coll))))]
  (map #(list (get-tag :c %) (get-tag :e (get-tag :d %)))
       (map :content (:content (clojure.xml/parse "foo.xml")))))

results in

((["ctext1"] ["etext1"]) (["ctext2"] ["etext2"]))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!