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.
许多博客都引用了clojure.xml / emit(或clojure.contrib.lazy-xml / emit)函数,但它似乎没有出现在1.2文档中。
Was it deprecated? What has replaced it?
它被弃用了吗?什么取代了它?
Can it be used to write Clojure-encoded XML (e.g.: {:tag :address :content {:tag :street ...} }
)?
它可以用来编写Clojure编码的XML(例如:{: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
.
更新:我查看了clojure.contrib.lazy-xml / emit的源代码(由Chris Houser提供),虽然它也不是“官方”,但它看起来比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.
顺便说一句,我已经“发现”了clojure和clojure-contrib源代码,这是一个写得很好,惯用语Clojure的好例子(特别是大师,Rich Hickey,两个Stuarts,Chris Houser等人写的部分)我会需要花一些时间来研究这些代码。
2 个解决方案
#1
5
Strangely enough, clojure.xml/emit
still exists when you (use 'clojure.xml)
that namespace at the REPL in 1.2.0.
奇怪的是,当您(使用'clojure.xml)在1.2.0中的REPL处使用该命名空间时,clojure.xml / emit仍然存在。
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
为了完全公开,我使用有用的(ns-map'用户)函数发现了这一点
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.
现在请注意,对于除了prxml之外的所有文件,你完全正确地从1.2(clojure.xml和clojure.contrib.lazy-xml)中的文档中消失了,这不是你想要的。我不能说出为什么会这样,但是在检查他们的文档字符串时,他们不再出现在Web界面中的原因变得明显。
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.
现在谷歌集团有这个线程,表明不鼓励使用emit函数有两个原因。
- It is undocumented and thus subject to change without notice.
- It, in general, does not produce valid xml (although I suppose if you know your data is valid it would emit valid xml).
它没有记录,因此如有变更,恕不另行通知。
它通常不会产生有效的xml(虽然我想如果你知道你的数据是有效的,它会发出有效的xml)。
At the end of that thread, Stuart Halloway talks about a project to extend Clojure's XML support.
在该主题结束时,Stuart Halloway谈到了一个扩展Clojure XML支持的项目。
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.
当然,总是潜入Java池并使用Java端的任何优秀的XML工具。听起来好像clojure的XML故事主要是在解析这一点时讲述的。
Hope that helps.
希望有所帮助。
#2
0
If you are running clojure 1.2, there is clojure.contrib.prxml.
如果您正在运行clojure 1.2,则有clojure.contrib.prxml。
If you are running clojure 1.3, the replacement is supposed to be https://github.com/clojure/data.xml
如果您正在运行clojure 1.3,则替换应该是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.
然而根据dev.clojure.org上的“哪里有clojure.contrib去”文档,新的lib还没有存储库,它可能是在某个地方构建并在maven repo中,但我无法找到它。虽然打包自己很容易。
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
我有一些使用prxml的遗留代码,所以我最终修复了prxml以使用Clojure 1.3,它位于clojars.org上https://clojars.org/weissjeffm/clojure.prxml
It's been working fine for me, but your mileage may vary.
它对我来说一直很好,但你的里程可能会有所不同。
#1
5
Strangely enough, clojure.xml/emit
still exists when you (use 'clojure.xml)
that namespace at the REPL in 1.2.0.
奇怪的是,当您(使用'clojure.xml)在1.2.0中的REPL处使用该命名空间时,clojure.xml / emit仍然存在。
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
为了完全公开,我使用有用的(ns-map'用户)函数发现了这一点
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.
现在请注意,对于除了prxml之外的所有文件,你完全正确地从1.2(clojure.xml和clojure.contrib.lazy-xml)中的文档中消失了,这不是你想要的。我不能说出为什么会这样,但是在检查他们的文档字符串时,他们不再出现在Web界面中的原因变得明显。
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.
现在谷歌集团有这个线程,表明不鼓励使用emit函数有两个原因。
- It is undocumented and thus subject to change without notice.
- It, in general, does not produce valid xml (although I suppose if you know your data is valid it would emit valid xml).
它没有记录,因此如有变更,恕不另行通知。
它通常不会产生有效的xml(虽然我想如果你知道你的数据是有效的,它会发出有效的xml)。
At the end of that thread, Stuart Halloway talks about a project to extend Clojure's XML support.
在该主题结束时,Stuart Halloway谈到了一个扩展Clojure XML支持的项目。
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.
当然,总是潜入Java池并使用Java端的任何优秀的XML工具。听起来好像clojure的XML故事主要是在解析这一点时讲述的。
Hope that helps.
希望有所帮助。
#2
0
If you are running clojure 1.2, there is clojure.contrib.prxml.
如果您正在运行clojure 1.2,则有clojure.contrib.prxml。
If you are running clojure 1.3, the replacement is supposed to be https://github.com/clojure/data.xml
如果您正在运行clojure 1.3,则替换应该是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.
然而根据dev.clojure.org上的“哪里有clojure.contrib去”文档,新的lib还没有存储库,它可能是在某个地方构建并在maven repo中,但我无法找到它。虽然打包自己很容易。
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
我有一些使用prxml的遗留代码,所以我最终修复了prxml以使用Clojure 1.3,它位于clojars.org上https://clojars.org/weissjeffm/clojure.prxml
It's been working fine for me, but your mileage may vary.
它对我来说一直很好,但你的里程可能会有所不同。