Skip to content

Instantly share code, notes, and snippets.

@foxdonut
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxdonut/13f33b3963a96a8aaf0d to your computer and use it in GitHub Desktop.
Save foxdonut/13f33b3963a96a8aaf0d to your computer and use it in GitHub Desktop.
(ns sample (:require [clojure.data.xml :as data.xml] [clojure.java.io :as io]))
(defn get-contact-info
"Extract info from tag"
[content tag]
(-> (filter #(= tag (:tag %)) content) first :content first))
(defn process-contact
"I don't do a whole lot."
[contact]
(let [get-info (partial get-contact-info (:content contact))]
{:id (:id (:attrs contact))
:first-name (get-info :first)
:last-name (get-info :last)
:email-address (get-info :email)})
;{:id (:id (:attrs contact)) :first-name (:first (:content contact)) :last-name (:last (:content contact)) :email-address (:email (:content contact)) :raw contact}
;{:id (:id (:attrs contact)) :first-name (:first (:content contact)) :last-name (:last (:content contact)) :email-address (:email (:content contact)) :raw contact}
)
(defn contact-seq
"Test"
[rdr]
(->> (:content (data.xml/parse rdr))
(filter #(= :contact (:tag %)))
(map process-contact)))
(defn run-sample
"FUN"
[]
(contact-seq (io/input-stream "contacts.xml")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment