(defn parse-seq
"Parses the source s, which can be a File, InputStream or String
naming a URI. Returns a lazy sequence of maps with two or more of
the keys :type, :name, :attrs, and :str. Other SAX-compatible
parsers can be supplied by passing startparse, a fn taking a source
and a ContentHandler and returning a parser. If a parser is
specified, it will be run in a separate thread and be allowed to get
ahead by queue-size items, which defaults to maxint. If no parser
is specified and org.xmlpull.v1.XmlPullParser is in the classpath,
this superior pull parser will be used."
([s] (if has-pull
(parse-seq-pull s)
(parse-seq s startparse-sax)))
([s startparse] (parse-seq s startparse Integer/MAX_VALUE))
([s startparse queue-size]
(let [s (if (instance? Reader s) (InputSource. s) s)
f (fn filler-func [fill]
(startparse s (proxy [DefaultHandler] []
(startElement [uri local-name q-name ^Attributes atts]
;(prn :start-element q-name)(flush)
(let [attrs (into {} (for [i (range (.getLength atts))]
[(keyword (.getQName atts i))
(.getValue atts i)]))]
(fill (struct node :start-element (keyword q-name) attrs))))
(endElement [uri local-name q-name]
;(prn :end-element q-name)(flush)
(fill (struct node :end-element (keyword q-name))))
(characters [ch start length]
;(prn :characters)(flush)
(let [st (String. ch start length)]
(when (seq (.trim st))
(fill (struct node :characters nil nil st))))))))]
(fill-queue f :queue-size queue-size))))
Vars in
clojure.contrib.lazy-xml/parse-seq:
defn
let
Used in 0 other vars
Comments top
No comments for parse-seq. Log in to add a comment.