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

0 votes
in data.xml by
In data.xml, there is currently no feature, equivalent to `xmlns="..."` on an xml tag. A tag in the empty namespace is kept as such.

(emit-str {:tag :xmlns.goo/foo
           :attrs {:xmlns "goo"}
           :content [
             {:tag :foo}]})

evaluates to

"<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo xmlns=\"goo\"><foo xmlns=\"\" xmlns:a=\"goo\"/></foo>"

-for a reason: to have perfect round-trippability and value equality for parsed xml-

However, mapping the empty namespace to a default namespace is valid for many use cases, including:

- notational brevity
- processing output from an HTML parser

Even though, notational brevity looks like a use case, that could benefit from the lexical scoping, a macro can provide, there is no clear use case and the reduced possibility of using arbitrary code in an xml fragment would probably make this inconvenient to use.

Processing, on the other hand, needs a dynamically scoped transformation, and lots of use cases for notational brevity can also be implemented with this.

So the use cases for implementing a dynamically scoped transformation are good.
As for API, setting an :xmlns attribute seems desirable for a couple of reasons:

- no interference with round-tripping:
  the above, striken-through reason doesn't apply, because the parser will never yield fragments with :xmlns attributes included
- limited effect on compositionality:
  setting an :xmlns attribute would be indistinguishable from applying a transformation, dynamically scoped down to another :xmlns.
- negligible API breakage (for -alpha)
  The current use case for setting an :xmlns attribute is a shortcut for setting it into metadata. It:
  - is a subset of the new behavior,
  - only breaks when trying to embed non-namespaced xml into a fragment with an overridden :xmlns (unlikely)
  - can be replicated with a function, setting metadata
- knowledge transfer from xml syntax

Therefore, the dynamically scoped default-xmlns feature should be exposed via setting :xmlns attributes for the emitter.

https://dev.clojure.org/display/DXML/Namespaced+XML should be updated, to reflect this rationale.

DXML-43 already suggested this, so that will be re-opened as well.

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/DXML-52 (reported by bendlas)