summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-12-18 19:43:21 +0000
committerRich Hickey <richhickey@gmail.com>2007-12-18 19:43:21 +0000
commit6213b1f8f984d5cd46d51608c9e7c30f78d8a68b (patch)
tree1fec03f6284bf0db3eb9c8741622cc0183c4780a /src
parentd7f632a51601b404c7ff879460aaa27848ae3ef1 (diff)
formatting
Diffstat (limited to 'src')
-rw-r--r--src/xml.clj72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/xml.clj b/src/xml.clj
index a0dfce02..0727e710 100644
--- a/src/xml.clj
+++ b/src/xml.clj
@@ -23,46 +23,46 @@
(def content (accessor element :content))
(def content-handler
- (new clojure.lang.XMLHandler
- (implement [ContentHandler]
- (startElement [uri local-name q-name #^Attributes atts]
- (let [attrs (fn [ret i]
- (if (neg? i)
- ret
- (recur (assoc ret
- (. clojure.lang.Keyword (intern (sym (. atts (getQName i)))))
- (. atts (getValue i)))
- (dec i))))
- e (struct element
- :tag (. clojure.lang.Keyword (intern (sym q-name)))
- :attrs (when (pos? (. atts (getLength)))
- (attrs {} (dec (. atts (getLength))))))]
- (set! *stack* (conj *stack* *current*))
- (set! *current* e)
- (set! *state* :element))
- nil)
- (endElement [uri local-name q-name]
- (let [push-content (fn [e c]
- (assoc e :content (conj (or (:content e) []) c)))]
- (when (eql? *state* :chars)
- (set! *current* (push-content *current* (str *sb*))))
- (set! *current* (push-content (peek *stack*) *current*))
- (set! *stack* (pop *stack*))
- (set! *state* :between))
- nil)
- (characters [ch start length]
- (when-not (eql? *state* :between)
- (when (eql? *state* :element)
- (set! *sb* (new StringBuilder)))
- (let [#^StringBuilder sb *sb*]
- (. sb (append ch start length))
- (set! *state* :chars)))
- nil))))
+ (new clojure.lang.XMLHandler
+ (implement [ContentHandler]
+ (startElement [uri local-name q-name #^Attributes atts]
+ (let [attrs (fn [ret i]
+ (if (neg? i)
+ ret
+ (recur (assoc ret
+ (. clojure.lang.Keyword (intern (sym (. atts (getQName i)))))
+ (. atts (getValue i)))
+ (dec i))))
+ e (struct element
+ :tag (. clojure.lang.Keyword (intern (sym q-name)))
+ :attrs (when (pos? (. atts (getLength)))
+ (attrs {} (dec (. atts (getLength))))))]
+ (set! *stack* (conj *stack* *current*))
+ (set! *current* e)
+ (set! *state* :element))
+ nil)
+ (endElement [uri local-name q-name]
+ (let [push-content (fn [e c]
+ (assoc e :content (conj (or (:content e) []) c)))]
+ (when (eql? *state* :chars)
+ (set! *current* (push-content *current* (str *sb*))))
+ (set! *current* (push-content (peek *stack*) *current*))
+ (set! *stack* (pop *stack*))
+ (set! *state* :between))
+ nil)
+ (characters [ch start length]
+ (when-not (eql? *state* :between)
+ (when (eql? *state* :element)
+ (set! *sb* (new StringBuilder)))
+ (let [#^StringBuilder sb *sb*]
+ (. sb (append ch start length))
+ (set! *state* :chars)))
+ nil))))
(defn parse [s]
(let [p (.. SAXParserFactory (newInstance) (newSAXParser))]
(binding [*stack* nil
- *current* (struct element)
+ *current* (struct element)
*state* :between
*sb* nil]
(. p (parse s content-handler))