<< Back to previous view

[DXML-43] Emitting XML element with :xmlns attribute doesn't work as expected Created: 25/Mar/17  Updated: 27/Mar/17  Resolved: 27/Mar/17

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Yegor Timoshenko Assignee: Ryan Senior
Resolution: Declined Votes: 0
Labels: None

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)


Affects version 0.2.0-alpha2, 0.0.8 doesn't have this problem.

user=> (require '[clojure.data.xml :as xml])
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>"

Comment by Herwig Hochleitner [ 27/Mar/17 2:40 AM ]

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

Comment by Yegor Timoshenko [ 27/Mar/17 6:31 AM ]

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"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
    <Description about="urn:mozilla:install-manifest">
Comment by Yegor Timoshenko [ 27/Mar/17 6:32 AM ]

...and then updated to 0.2.0.

Comment by Herwig Hochleitner [ 27/Mar/17 9:56 AM ]

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.

Comment by Herwig Hochleitner [ 27/Mar/17 10:01 AM ]

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})

Generated at Tue Mar 28 14:58:20 CDT 2017 using JIRA 4.4#649-r158309.