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

0 votes
in data.xml by
Affects version 0.2.0-alpha2, 0.0.8 doesn't have this problem.

user=> (require '[clojure.data.xml :as xml])
nil
user=> (xml/emit-str {:tag :RDF :attrs {:xmlns "http://www.w3.org/1999/02/22-rdf-syntax-ns"}})
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><RDF></RDF>"

10 Answers

0 votes
by

Comment made by: bendlas

Works as designed: Since you're emitting a plain, non-namespaced element, called RDF, it's impossible to set a default xmlns.

0 votes
by

Comment made by: yegortimoshenko

It's a regression. It breaks your code if you've used data.xml to generate the following XML using version 0.0.8:

`
<?xml version="1.0" encoding="utf-8"?>

<Description about="urn:mozilla:install-manifest">
      <em:id>jid1-3MbuIoOYk03BMg@jetpack</em:id>
</Description>


`

0 votes
by

Comment made by: yegortimoshenko

...and then updated to 0.2.0.

0 votes
by
_Comment made by: bendlas_

0.0.8 didn't have xmlns support at all, hence this is not considered a regression (we couldn't even roundtrip namespaced XML). To be able to emit namespaced XML like this was incidental.

0.2.0 established semantics for XML namespaces, part of which say that {:tag :RDF} _always_ means <RDF> (in the empty namespace), in order to facilitate composition. Please read up on the current semantics in the README and in the Design Page http://dev.clojure.org/display/DXML/Namespaced+XML

We are still in -alpha, so if you have ideas for changing the semantics, feel free to state your case with reference to the current design.
0 votes
by
_Comment made by: bendlas_

btw, with current xmlns support, you would write your fragment like:


(alias-uri 'R "http://www.w3.org/1999/02/22-rdf-syntax-ns")
(emit-str {:tag ::R/RDF})
0 votes
by
_Comment made by: brutasse_

With -alpha5, this generates prefixed tags/attrs:

{{<?xml version="1.0" encoding="UTF-8"?><a:RDF xmlns:a="http://www.w3.org/1999/02/22-rdf-syntax-ns"/>}}

How would one emit {{<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns"/>}} with 0.2?
0 votes
by
_Comment made by: bendlas_

Since any non-broken xml consumer shouldn't care about that difference, data.xml emits prefixes at will.
It does, however, try to keep emitted prefixes to a minimum and you can exploit that behavior to get the serialisation, you want:

(alias-uri 'R "http://www.w3.org/1999/02/22-rdf-syntax-ns")
(emit-str {:tag ::R/RDF :attrs {:xmlns "http://www.w3.org/1999/02/22-rdf-syntax-ns"}})

emits

<?xml version="1.0" encoding="UTF-8"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns"/>
0 votes
by

Comment made by: brutasse

Thank you. We have to cope with a host of XML consumers in many languages, broken in various ways so it's very important to have complete control over the output.

For now we've reverted to 0.0.8. We'll see if we switch to the * } notation but it's less pleasant to read.

0 votes
by

Comment made by: bendlas

I was thinking about a replacement mechanism for your use case. Turns out, I was wrong about declining this. See DXML-52 for a rationale.

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