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

0 votes
in data.xml by

The goal is to emit XML with namespaces aggregated at the document root, and with prefixes customised. data.xml provides {{aggregate-xmlns}} for this. Unfortunately it seems to interfere with xmlns prefix {{:attrs}}.

To reproduce first set up some test data:

`
(xml/alias-uri 'foo "http://foo", 'bar "http://bar")

(def document
(xml/element ::foo/x {}

(xml/element ::bar/y {} "...")))

`

Namespace aggregation with {{(xml/aggregate-xmlns document)}} works fine, but now I would like to customise the prefixes. Here the {{:attrs}} seem to have no effect:

`
(xml/emit-str
(-> (xml/aggregate-xmlns document)

  (assoc-in [:attrs :xmlns/bar] "http://bar")
  (assoc-in [:attrs :xmlns/foo] "http://foo")))

`

`
<?xml version="1.0" encoding="UTF-8"?>
<a:x xmlns:a="http://foo" xmlns:b="http://bar">

<b:y>...</b:y>

</a:x>
`

Doing {{aggregate-xmlns}} last instead throws an exception:

`
(xml/emit-str
(xml/aggregate-xmlns

(-> document
    (assoc-in [:attrs :xmlns/bar] "http://bar")
    (assoc-in [:attrs :xmlns/foo] "http://foo"))))

`

ExceptionInfo The xmlns binding for prefix `xmlns` is fixed to `http://www.w3.org/2000/xmlns/` clojure.core/ex-info

I could verify that the right prefixes are generated when I leave {{aggregate-xmlns}} out of the picture - but aggregation is the goal.

3 Answers

0 votes
by

Comment made by: bendlas

OK, thanks for the report! I'll take a look later ..

0 votes
by
_Comment made by: glts_

And by the way, not sure why {{aggregate-xmlns}} always generates new prefixes for the aggregated namespaces? Wouldn’t it be better to preserve encountered prefixes as much as possible?

That is, if somewhere in the tree there is an element {{<foo:x xmlns:foo="http://foo" />}} I would expect this namespace to be aggregated in the root with prefix {{foo}} … that way emit will automatically generate the expected prefixes.
0 votes
by
Reference: https://clojure.atlassian.net/browse/DXML-55 (reported by glts)
...