Last active
August 29, 2015 14:05
-
-
Save foxdonut/13f33b3963a96a8aaf0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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