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

0 votes
in data.xml by
retagged by

Using aggregate-xmlns with larger xml trees causes the following exception:

Execution error (ExceptionInfo) at clojure.data.xml.name/legal-xmlns-binding! (name.cljc:151).
The xmlns binding for prefix `xml` is fixed to `http://www.w3.org/XML/1998/namespace`

aggregate-xmlns creates a new prefix for each tag with gen-prefix:

     (binding [*gen-prefix-counter* 0]
       (-> (fn [tm uri]
             (pu/assoc! tm (gen-prefix) uri))
           (reduce-tree (pu/transient pu/EMPTY) xml)

gen-prefix itself just deterministically joins characters to make up a new prefix string, e.g. "a", "b", "c" ...

Unfortunately the 7771th iteration generates the prefix string "xml", which is illegal to use and is rejected in clojure.data.xml.pu-map/assoc! by the check in (name/legal-xmlns-binding! prefix uri), causing the above quoted exception. The same problem will happen later for "xmlns".

An easy workaround is to not do the checks in case the uri is blank.


A quick reproducer is:

    (xml/aggregate-xmlns (xml/element* :coll {} (repeatedly #(xml/element :el))))

1 Answer

0 votes