Jesús Gómez / Oct 16 2020
XML alias-uri problem
{:deps {org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}}}
deps.edn
Extensible Data Notation
Description
This snippet works on a console and is extracted verbatim from the data.xml documentation. But here we have a problem.
If you try to run this cell from a fresh Runtime, you will get an error with the message Invalid token: ::xh/html:
(require [clojure.data.xml :refer :all])
(alias-uri xh "http://www.w3.org/1999/xhtml")
(emit-str {:tag ::xh/html
:content [{:tag ::xh/head} {:tag ::xh/body :content ["DOCUMENT"]}]})
0.9s
Clojure
Explanation
Nextjournal support actually checked this.
This is what they are suspecting is happening:
"I think this is an issue with the context of how cells are run, in that the alias does not affect code within the same cell. I was able to get it to run by moving the emit-str
to its own cell." - Nextjournal support
So I also tried what they tried (run alias-uri
and emit-str
in different cells) and it works:
(require [clojure.data.xml :refer :all])
(alias-uri xh "http://www.w3.org/1999/xhtml")
2.8s
Clojure
nil
(emit-str {:tag ::xh/html
:content [{:tag ::xh/head} {:tag ::xh/body :content ["DOCUMENT"]}]})
0.3s
Clojure
"<?xml version="1.0" encoding="UTF-8"?><a:html xmlns:a="http://www.w3.org/1999/xhtml"><a:head/><a:body>DOCUMENT</a:body></a:html>"