Fix clojure.xml/emit-element for simple XML serialization

98 views
Skip to first unread message

Yrjö Kari-Koskinen

unread,
Oct 12, 2015, 3:45:18 PM10/12/15
to Clojure Dev
Hi all,

I would like to post a patch (and tests) to clojure.xml/emit-element that would fix the case where either the element string content or attribute value has characters that need to be escaped in xml ('&<>").

I feel that the emit-element should be fixed as the clojure.xml/parse is anyways used and supported. This way there would be a decent roundtrip support for simple namespaceless XML serialization. In my case, I use clj-tagsoup/parse-xml which uses clojure.xml/parse to parse HTML which I need finally to serializa as well.

Cheers,
- Ykä

Alex Miller

unread,
Oct 12, 2015, 4:09:04 PM10/12/15
to cloju...@googlegroups.com
Hi Ykä,

You can file a jira ticket for this. I think there are a number of things to consider - should this escaping happen during parsing, during emitting, or as a separate utility? (considering perf in all those cases). Also, you should consider other existing oss escapers like those in Guava and Apache Commons. We would not add a dependency to those libs but there is precedent for pulling files from other oss projects into Clojure in a few cases (like Murmur3 from Guava).

Alex



--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.

Yrjö Kari-Koskinen

unread,
Oct 13, 2015, 4:12:39 PM10/13/15
to Clojure Dev
Hi,

the current clojure.xml/parse implementation uses Java's SAX Parser and thus de-escapes the aforementioned characters as well as CDATA sections, so I would keep the emit method symmetrical and during emitting escape only the characters mentioned in the XML spec. The escaping is very simple and can be done in a namespace local utility method.

But: I found these old tickets CLJ-408, CLJ-410 and CLJ-411 with Stuart Halloway's comment: "emit is not part of Clojure's public API, and we don't want to grow a public API via an issue-driven random walk. If you are interested in this issue, please chime in on the design page for a new data.xml library: http://dev.clojure.org/display/DXML/Home".

So is that comment still valid: is this kind of fix to emit not desired?

Cheers,
 - Ykä
Reply all
Reply to author
Forward
0 new messages