Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

57 lines (47 sloc) 2.007 kb
; Copyright (c) Chris Houser, Dec 2008. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
; optional module to allow lazy-xml to use pull parser instead of sax
(in-ns 'clojure.contrib.lazy-xml)
(import '(org.xmlpull.v1 XmlPullParser XmlPullParserFactory))
(defn- attrs [xpp]
(for [i (range (.getAttributeCount xpp))]
[(keyword (.getAttributeName xpp i))
(.getAttributeValue xpp i)]))
(defn- ns-decs [xpp]
(let [d (.getDepth xpp)]
(for [i (range (.getNamespaceCount xpp (dec d)) (.getNamespaceCount xpp d))]
(let [prefix (.getNamespacePrefix xpp i)]
[(keyword (str "xmlns" (when prefix (str ":" prefix))))
(.getNamespaceUri xpp i)]))))
(defn- attr-hash [xpp]
(into {} (concat (ns-decs xpp) (attrs xpp))))
(defn- pull-step [xpp]
(case (.next xpp)
(lazy-cons (struct node :start-element
(keyword (.getName xpp))
(attr-hash xpp))
(pull-step xpp))
(lazy-cons (struct node :end-element
(keyword (.getName xpp)))
(pull-step xpp))
(let [text (.trim (.getText xpp))]
(if (seq text)
(lazy-cons (struct node :characters nil nil text)
(pull-step xpp))
(recur xpp)))))
(def #^{:private true} factory
(doto (XmlPullParserFactory/newInstance)
(.setNamespaceAware true)))
(defn- parse-seq-pull [s]
(let [xpp (.newPullParser factory)]
(.setInput xpp s)
(pull-step xpp)))
(def has-pull true)
Jump to Line
Something went wrong with that request. Please try again.