开发者

What happened to clojure.xml/emit?

Many blogs refer to the clojure.xml/emit (or clojure.contrib.lazy-xml/emit) function, but it seems to be absent from the 1.2 documentation.

Was it deprecated? What has replaced it?

Can it be used to write Clojure-encoded XML (e.g.: {:tag :address :content {:tag :street ...} })?

UPDATE: I looked at the source code for clojure.contrib.lazy-xml/emit (by Chris Houser) and, although it too is not "official", it looks like a more stable solution than clojure.xml/emit.

BTW, I have "discovered" the clojure and clojure-contrib source code as great examples of well-written, idiomatic Clojure (especially the parts written by the masters, Rich Hickey, the two Stuarts, Chris Houser, etc.) I'll 开发者_StackOverflow社区need to spend some time studying that code.


Strangely enough, clojure.xml/emit still exists when you (use 'clojure.xml) that namespace at the REPL in 1.2.0.

To verify:

user=> (use 'clojure.xml)
user=> (emit (parse "http://feeds.feedburner.com/burningonesblog"))

For full disclosure I discovered this using the useful (ns-map 'user) function

user=> (doc ns-map)
-------------------------
clojure.core/ns-map
([ns])
  Returns a map of all the mappings for the namespace.
nil

Now please note that you are entirely correct about their disappearing from the documentation in 1.2 (clojure.xml and clojure.contrib.lazy-xml) for all but prxml which isn't really what you're looking for. I can't speak to why that is the case but the reason they no longer show up in the web interface becomes evident upon examining their docstring.

user=> (doc emit)
-------------------------
clojure.xml/emit
([x])
  nil
nil

Now there is this thread over at the Google Group which indicates that use of the emit function is discouraged for 2 reasons.

  1. It is undocumented and thus subject to change without notice.
  2. It, in general, does not produce valid xml (although I suppose if you know your data is valid it would emit valid xml).

At the end of that thread, Stuart Halloway talks about a project to extend Clojure's XML support.

Of course there's always dipping into the Java pool and using any of the excellent XML tools on the Java end. It sounds like clojure's XML story is mostly told in parsing at this point.

Hope that helps.


If you are running clojure 1.2, there is clojure.contrib.prxml.

If you are running clojure 1.3, the replacement is supposed to be https://github.com/clojure/data.xml

However according to "Where did clojure.contrib go" document on dev.clojure.org, the new lib does not have a repository yet, it may be built and in a maven repo somewhere, but I wasn't able to find it. It is pretty easy to package yourself though.

I had some legacy code that used prxml, so I ended up just fixing up prxml to work with Clojure 1.3, it's on clojars.org https://clojars.org/weissjeffm/clojure.prxml

It's been working fine for me, but your mileage may vary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜