Skip to content

Instantly share code, notes, and snippets.

@zamaterian
Created March 8, 2012 08:16
Show Gist options
  • Save zamaterian/1999613 to your computer and use it in GitHub Desktop.
Save zamaterian/1999613 to your computer and use it in GitHub Desktop.
hacks of zip xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<subtitle>A subtitle.</subtitle>
<link href="http://example.org/feed/" rel="self" />
<link href="http://example.org/" />
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
<email>[email protected]</email>
</author>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03" />
<link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
<link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>
...
The code is just cut and pasted from some midje test.
...
(:require [clojure.data.zip.xml :as zip :only [xml-> text]]
[clojure.xml :as xml]
[clojure.zip :as zipper])
(defn zip-str [s]
(zipper/xml-zip (xml/parse (java.io.ByteArrayInputStream. (.getBytes s)))))
(let [xml (zip-str "<xml> .... </xml>") ]
(zip/xml-> xml :link [(zip/attr= :rel "self")] zip/text)) ; finds the link node with rel = self
[org.clojure/data.zip "0.1.0"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment