What happened to closure.xml/emit?

送分小仙女□ 提交于 2019-12-23 15:22:49

问题


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 need to spend some time studying that code.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4440523/what-happened-to-closure-xml-emit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!