diff options
author | Chouser <chouser@n01se.net> | 2009-02-22 01:16:40 +0000 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-02-22 01:16:40 +0000 |
commit | 8cd98884452912454d297f217e0840d84553c49c (patch) | |
tree | 0803a218a96961123f6baac31181a8084f592c74 /src | |
parent | 46a05fd000b4123fae3a9a4b2762f73908e52409 (diff) |
lazy-xml: update for lazier Clojure
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/lazy_xml.clj | 3 | ||||
-rw-r--r-- | src/clojure/contrib/lazy_xml/with_pull.clj | 34 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/clojure/contrib/lazy_xml.clj b/src/clojure/contrib/lazy_xml.clj index f8b07fe0..f309e5f6 100644 --- a/src/clojure/contrib/lazy_xml.clj +++ b/src/clojure/contrib/lazy_xml.clj @@ -22,7 +22,8 @@ ; http://www.extreme.indiana.edu/xgws/xsoap/xpp/ (def has-pull false) (defn- parse-seq-pull [& _]) -(try (load "lazy_xml/with_pull") +(try + (load "lazy_xml/with_pull") (catch Exception e (when-not (re-find #"XmlPullParser" (str e)) (throw e)))) diff --git a/src/clojure/contrib/lazy_xml/with_pull.clj b/src/clojure/contrib/lazy_xml/with_pull.clj index 7d70d479..06181569 100644 --- a/src/clojure/contrib/lazy_xml/with_pull.clj +++ b/src/clojure/contrib/lazy_xml/with_pull.clj @@ -27,22 +27,24 @@ (into {} (concat (ns-decs xpp) (attrs xpp)))) (defn- pull-step [xpp] - (case (.next xpp) - XmlPullParser/START_TAG - (lazy-cons (struct node :start-element - (keyword (.getName xpp)) - (attr-hash xpp)) - (pull-step xpp)) - XmlPullParser/END_TAG - (lazy-cons (struct node :end-element - (keyword (.getName xpp))) - (pull-step xpp)) - XmlPullParser/TEXT - (let [text (.trim (.getText xpp))] - (if (seq text) - (lazy-cons (struct node :characters nil nil text) - (pull-step xpp)) - (recur xpp))))) + (let [step (fn [xpp] + (condp = (.next xpp) + XmlPullParser/START_TAG + (cons (struct node :start-element + (keyword (.getName xpp)) + (attr-hash xpp)) + (pull-step xpp)) + XmlPullParser/END_TAG + (cons (struct node :end-element + (keyword (.getName xpp))) + (pull-step xpp)) + XmlPullParser/TEXT + (let [text (.trim (.getText xpp))] + (if (empty? text) + (recur xpp) + (cons (struct node :characters nil nil text) + (pull-step xpp))))))] + (lazy-seq (step xpp)))) (def #^{:private true} factory (doto (XmlPullParserFactory/newInstance) |