Last active
September 20, 2019 19:45
-
-
Save gistlyn/69a8c68fb2315acc4cd079e3fe1bba51 to your computer and use it in GitHub Desktop.
Simple #Script Lisp RSS Parser
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
(defn parse-rss [xml] | |
(let ( (to) (doc) (channel) (items) (el) ) | |
(def doc (System.Xml.Linq.XDocument/Parse xml)) | |
(def to (ObjectDictionary.)) | |
(def items (List<ObjectDictionary>.)) | |
(def channel (first (.Descendants doc "channel"))) | |
(def el (XLinqExtensions/FirstElement channel)) | |
; retrieve all elements up to the first <item> as top-level entries | |
(while (not= (.LocalName (.Name el)) "item") | |
(.Add to (.LocalName (.Name el)) (.Value el)) | |
(def el (XLinqExtensions/NextElement el))) | |
; add all rss item's to items collection | |
(doseq (elItem (.Descendants channel "item")) | |
(def item (ObjectDictionary.)) | |
(def el (XLinqExtensions/FirstElement elItem)) | |
(while el | |
(.Add item (.LocalName (.Name el)) (.Value el)) | |
(def el (XLinqExtensions/NextElement el))) | |
(.Add items item)) | |
(.Add to "items" items) | |
to | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment