Skip to content

Instantly share code, notes, and snippets.

Last active April 3, 2020 08:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
I'm trying to learn to use clojure to parse a wordpress XML and generate markdown files for each one.
; add a basic namespace, I guess
(ns thingo.core)
(require '[ :as io])
(require '[clojure.xml :as xml])
(require '[ :as zip])
(require '[ :as zip-xml])
(require '[clojure.pprint :refer pprint :as pp])
(def blog-file "./path-to-wordpress-export-file.xml")
(def root (-> blog-file
; I want a vector of maps, where each map has all the attributes of the items.
(def posts (zip-xml/xml-> root :channel
:item [(keyword "wp:post_type") "post"]))
(defn post->map
"Return a map for the corresponding post we pass in."
{:title (zip-xml/xml1-> post :title zip-xml/text)
:content (zip-xml/xml1-> post (keyword "content:encoded") zip-xml/text)})
; inspect a single post
(let [[post & rest] posts]
(post->map post))
; iterate through the posts
(pp (for [post posts]
(post->map post)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment