Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in data.xml by

I'm slowly converting some code from using xml/element to xml/sexp-as-element, and I've noticed a discrepancy. xml/element does (almost) no processing of the "content", inserting it directly (unless it's nil). xml/sexp-as-element calls (str) on the "content" if it's not seq of some kind (vector or ISeq) or a keyword. This means that (= (xml/element :foo {} 1) (xml/sexp-as-element [:foo 1])) is false.

There are probably other differences, but this one seems relatively big, as there's no way to use numbers in xml/sexp-as-element without calling extend-protocol yourself.

May I recommend/request adding this extension? It will make xml/sexp-as-element match xml/element for numbers, and make xml/sexp-as-element match hiccup in general.

(extend-protocol clojure.data.xml.protocols/AsElements
  java.lang.Number
  (as-elements [n] [n]))
ago by
On the other hand, ... Short of XML Schema, does XML have numbers? This might be a case of questionable permissiveness in clojure.data.xml/element, rather than over-coercion in sexp-as-element.
ago by
edited ago by
Oh yeah, that's a great point. I'll do more research but I believe after a cursory look that you're correct: all "content" is considered text (unless it's another tag).
ago by
That was my first reaction as well. Seems like content should generally be considered as a string, so maybe it's the xml/element constructor doing the wrong thing here.

Please log in or register to answer this question.

...