Last active
August 29, 2015 14:05
-
-
Save scarcher2/545455d84bfbaeb5aab3 to your computer and use it in GitHub Desktop.
Sample Code
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
<?xml version="1.0"?> | |
<contact_list> | |
<contact id="1"> | |
<first>Joe</first> | |
<last>Smith</last> | |
<email>joe@example.com</email> | |
</contact> | |
<contact id="2"> | |
<first>Jane</first> | |
<last>Smith</last> | |
<email>jane@example.com</email> | |
</contact> | |
<contact id="3"> | |
<first>John</first> | |
<last>Smith</last> | |
<email>John@example.com</email> | |
</contact> | |
</contact_list> |
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.core (:require [clojure.data.xml :as data.xml] [clojure.java.io :as io])) | |
(defn process-contact | |
"I don't do a whole lot." | |
[contact] | |
{: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"))) |
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
({:raw #clojure.data.xml.Element{:tag :contact, :attrs {:id "1"}, :content (#clojure.data.xml.Element{:tag :first, :attrs {}, :content ("Joe")} #clojure.data.xml.Element{:tag :last, :attrs {}, :content ("Smith")} #clojure.data.xml.Element{:tag :email, :attrs {}, :content ("joe@example.com")})}} {:raw #clojure.data.xml.Element{:tag :contact, :attrs {:id "2"}, :content (#clojure.data.xml.Element{:tag :first, :attrs {}, :content ("Jane")} #clojure.data.xml.Element{:tag :last, :attrs {}, :content ("Smith")} #clojure.data.xml.Element{:tag :email, :attrs {}, :content ("jane@example.com")})}} {:raw #clojure.data.xml.Element{:tag :contact, :attrs {:id "3"}, :content (#clojure.data.xml.Element{:tag :first, :attrs {}, :content ("John")} #clojure.data.xml.Element{:tag :last, :attrs {}, :content ("Smith")} #clojure.data.xml.Element{:tag :email, :attrs {}, :content ("John@example.com")})}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment