Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn render
- "Do the hard work for core/xml"
- [document xmlns nss nodes]
- (letfn [(make-node [root [tag & nodes :as total]]
- (let [prefix (namespace tag)
- tag (name tag)]
- (let [ele (if-let [uri (and prefix (get nss prefix))]
- (.createElementNS document uri (str prefix \: tag))
- (.createElement document tag))]
- (doseq [[k v] (meta total)]
- (.setAttribute ele (name k) (str v)))
- (reduce
- (fn [f child]
- (fn []
- (.appendChild ele (inner-render ele child))
- f))
- #(do (.appendChild root ele) ele)
- nodes))))
- (inner-render [root node]
- (cond
- (coll? node) (make-node root node)
- (string? node) (.appendChild root (.createTextNode document node))
- (instance? org.w3c.dom.Element node) (.appendChild root node)
- (fn? node) node
- :else (recur root (str node))))]
- (let [root (.getDocumentElement document)]
- (doseq [node nodes]
- (.appendChild root (trampoline inner-render root node))))
- document))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement