Clojures clojure.xml/parse, clojure.zip/xml-zip and clojure.contrib.zip-filter.xml/xml-> are excellent tools for pulling values out of xml, but what if I want to change the xml (the result of clojure.zip/xml-zip) based on what I learn from xml-> “queries” and write the result back out as xml?
I would have expected that (clojure.contrib.prxml/prxml (clojure.xml/parse xml-content)) spit back xml, but that is not the case.
Update: Actually, for emitting XML, it’s best to use
clojure.contrib.lazy-xml/emit, becauseclojure.xml/emitis 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/emitandclojure.xml/emit-element:(
with-out-strcaptures printed output and wraps it up as a string; for some reasonxml/emitprints the xml, so it comes in handy here. You’ll want to useemit-elementif<?xml version='1.0' encoding='UTF-8'?>is not what you want.)