Mutating XML in Clojure
Update: Actually, for emitting XML, it's best to use clojure.contrib.lazy-xml/emit
, because clojure.xml/emit
is currently likely to break things! See my comment below.
(Leaving this answer here for now as a warning.)
If I understand correctly, the main thrust of the question has to do with turning the (possibly mutated) XML representation back into XML text?
If so, have a look at clojure.xml/emit
and clojure.xml/emit-element
:
user> (with-out-str (xml/emit {:tag :foo :attrs {:bar "quux"}}))"<?xml version='1.0' encoding='UTF-8'?>\n<foo bar='quux'/>\n"
(with-out-str
captures printed output and wraps it up as a string; for some reason xml/emit
prints the xml, so it comes in handy here. You'll want to use emit-element
if <?xml version='1.0' encoding='UTF-8'?>
is not what you want.)