What happened to closing .xml / emit?

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

Was it obsolete? What replaced him?

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

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

By the way, I “discovered” the source code of clojure and Clojure -contrib as a great example of a well-written, idiomatic clojure (especially parts written by masters, Rich Hickey, two Stuarts, Chris Houser, etc.) I need to spend some time studying this code.

+4
source share
2 answers

Oddly enough, clojure.xml/emit still exists when you (use 'clojure.xml) , this is the namespace in REPL in 1.2.0.

To check:

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

For full disclosure, I discovered this with a useful function (ns-map 'user)

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

Now notice that you are completely right that they disappeared from the documentation in 1.2 ( clojure.xml and clojure.contrib.lazy-xml ) for everyone except prxml , which isn’t really what you are looking for. I can’t talk about why this is so, but the reason why they no longer appear in the web interface becomes apparent when studying their documentation.

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

Now there is this thread in the Google Group that indicates that using the emit function emit not recommended for two reasons.

  • This is undocumented and therefore subject to change without notice.
  • It generally does not create valid xml (although I assume that if you know that your data is valid, it will produce valid xml).

At the end of this thread, Stuart Halloway talks about a project to expand support for Clojure XML.

Of course, he always plunges into the Java pool and uses any of the excellent XML tools at the end of Java. It seems that the Clojure XML story is mainly used for parsing at this point.

Hope this helps.

+5
source

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

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

However, according to “Where is the clojure.contrib go document” on dev.clojure.org, the new library does not yet have a repository, it can be built in the maven repo somewhere, but I was not able to find it. It is quite easy to pack yourself, though.

I had some legacy code that used prxml, so I just installed prxml to work with clojure 1.3, on clojars.org https://clojars.org/weissjeffm/clojure.prxml

It works great for me, but your mileage may vary.

0
source

Source: https://habr.com/ru/post/1332109/


All Articles