Skip to content

Instantly share code, notes, and snippets.

@mullr
Created April 10, 2013 03:30
Show Gist options
  • Save mullr/5351562 to your computer and use it in GitHub Desktop.
Save mullr/5351562 to your computer and use it in GitHub Desktop.
(ns xml-test
(:use [clojure.test]
[clojure.data.zip.xml])
(:require [clojure.xml :as xml]
[clojure.zip :as zip]))
(defn parse-str [s]
(zip/xml-zip (xml/parse (new org.xml.sax.InputSource
(new java.io.StringReader s)))))
(def atom1 (parse-str "<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'>
<id>tag:blogger.com,1999:blog-28403206</id>
<updated>2008-02-14T08:00:58.567-08:00</updated>
<title type='text'>n01senet</title>
<link rel='alternate' type='text/html' href='http://n01senet.blogspot.com/'/>
<entry>
<id>1</id>
<published>2008-02-13</published>
<title type='text'>clojure is the best lisp yet</title>
<author><name>Chouser</name></author>
</entry>
<entry>
<id>2</id>
<published>2008-02-07</published>
<title type='text'>experimenting with vnc</title>
<author><name>agriffis</name></author>
</entry>
</feed>
"))
(xml-> atom1 :entry :id text)
;; ("1" "2")
(xml-> atom1 :entry :published text)
;; ("2008-02-13" "2008-02-07")
;; (xml-> atom1 :entry ???????)
;; ({:id "1" :published "2008-02-13"} {:id "2" :published 2008-02-07})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment