• (emit e & {:as opts})

1 Example top

  • (require 'clojure.contrib.lazy-xml)
      {:tag :div 
       :attrs {:style "border:1px solid red"} 
       :content [{:tag :p :content ["This is a div"]}]}
      :indent 4)
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/lazy_xml.clj:139 top

(defn emit
  [e & {:as opts}]
  (let [content-handler (atom nil)
        trans (-> (javax.xml.transform.TransformerFactory/newInstance)

    (when (:indent opts)
      (.setOutputProperty trans "indent" "yes")
      (.setOutputProperty trans "{http://xml.apache.org/xslt}indent-amount"
                          (str (:indent opts))))

    (when (contains? opts :xml-declaration)
      (.setOutputProperty trans "omit-xml-declaration" 
                          (if (:xml-declaration opts) "no" "yes")))

    (when (:encoding opts)
      (.setOutputProperty trans "encoding" (:encoding opts)))

        (reify org.xml.sax.XMLReader
          (getContentHandler [_] @content-handler)
          (setDTDHandler [_ handler])
          (setFeature [_ name value])
          (setProperty [_ name value])
          (setContentHandler [_ ch] (reset! content-handler ch))
          (^void parse [_ ^org.xml.sax.InputSource _]
            (when @content-handler
              (.startDocument @content-handler)
              (emit-element e @content-handler)
              (.endDocument @content-handler))))
      (javax.xml.transform.stream.StreamResult. *out*))))
Vars in clojure.contrib.lazy-xml/emit: *out* contains? defn let reify reset! str when deref
Used in 0 other vars

Comments top

No comments for emit. Log in to add a comment.