Advertisement
Guest User

Untitled

a guest
Jun 19th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (clojure.data.xml/emit-str (element :e {:attr "x"} (element :e1) (element :e2)))
  2. ; Generates:
  3. ; "<?xml version=\"1.0\" encoding=\"UTF-8\"?><e attr=\"x\"><e1></e1><e2></e2></t>"
  4.  
  5. ; However, I need to generate elements from a data str, so I've something like:
  6.  
  7. (clojure.data.xml/emit-str (element :e
  8.                                     {:attr "x"}
  9.                                     (for [e '[:e1 :e2]]
  10.                                          (element e))))
  11.  
  12. ; which results in...
  13. ; IllegalArgumentException No implementation of method: :emit-element of protocol:
  14. ; #'clojure.data.xml/Emit found for class: clojure.lang.LazySeq  clojure.core/-cache-
  15. ; protocol-fn (core_deftype.clj:527)
  16. ;
  17. ; I.e., (element) doesn't destructure the result of the (for)
  18. ; I can see this if I use clojure.data.xml/emit instead of emit-str:
  19.  
  20. (pprint (element :e
  21.                  {:attr "x"}
  22.                  (for [e '[:e1 :e2]]
  23.                       (element e))))
  24.  
  25. ; This outputs:
  26. {:tag :e,
  27.  :attrs {:attr "x"},
  28.  :content
  29.  (({:tag :e1, :attrs {}, :content ()}
  30.    {:tag :e2, :attrs {}, :content ()}))}
  31.  
  32. ; which has the :e1 and :e2 elements in a superfluous seq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement