<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged clojure.data.xml</title>
<link>https://ask.clojure.org/index.php/tag/clojure.data.xml</link>
<description></description>
<item>
<title>Default implementation of AsElements to treat numbers as numbers, not strings</title>
<link>https://ask.clojure.org/index.php/15060/default-implementation-aselements-numbers-numbers-strings</link>
<description>&lt;p&gt;I'm slowly converting some code from using &lt;code&gt;xml/element&lt;/code&gt; to &lt;code&gt;xml/sexp-as-element&lt;/code&gt;, and I've noticed a discrepancy. &lt;code&gt;xml/element&lt;/code&gt; does (almost) no processing of the &quot;content&quot;, inserting it directly (unless it's &lt;code&gt;nil&lt;/code&gt;). &lt;code&gt;xml/sexp-as-element&lt;/code&gt; calls &lt;code&gt;(str)&lt;/code&gt; on the &quot;content&quot; if it's not seq of some kind (vector or ISeq) or a keyword. This means that &lt;code&gt;(= (xml/element :foo {} 1) (xml/sexp-as-element [:foo 1]))&lt;/code&gt; is false.&lt;/p&gt;
&lt;p&gt;There are probably other differences, but this one seems relatively big, as there's no way to use numbers in &lt;code&gt;xml/sexp-as-element&lt;/code&gt; without calling &lt;code&gt;extend-protocol&lt;/code&gt; yourself.&lt;/p&gt;
&lt;p&gt;May I recommend/request adding this extension? It will make &lt;code&gt;xml/sexp-as-element&lt;/code&gt; match &lt;code&gt;xml/element&lt;/code&gt; for numbers, and make &lt;code&gt;xml/sexp-as-element&lt;/code&gt; match hiccup in general.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(extend-protocol clojure.data.xml.protocols/AsElements
  java.lang.Number
  (as-elements [n] [n]))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>data.xml</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15060/default-implementation-aselements-numbers-numbers-strings</guid>
<pubDate>Tue, 28 Apr 2026 16:10:26 +0000</pubDate>
</item>
<item>
<title>clojure.data.xml/aggregate-xml generates invalid &quot;xml&quot; and &quot;xmlns&quot; prefixes</title>
<link>https://ask.clojure.org/index.php/12688/clojure-data-xml-aggregate-generates-invalid-xmlns-prefixes</link>
<description>&lt;p&gt;Using aggregate-xmlns with larger xml trees causes the following exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error (ExceptionInfo) at clojure.data.xml.name/legal-xmlns-binding! (name.cljc:151).
The xmlns binding for prefix `xml` is fixed to `http://www.w3.org/XML/1998/namespace`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;aggregate-xmlns creates a new prefix for each tag with &lt;code&gt;gen-prefix&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;     (binding [*gen-prefix-counter* 0]
       (-&amp;gt; (fn [tm uri]
             (pu/assoc! tm (gen-prefix) uri))
           qname-uri-xf
           (reduce-tree (pu/transient pu/EMPTY) xml)
           pu/persistent!))}))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;gen-prefix&lt;/code&gt; itself just deterministically joins characters to make up a new prefix string, e.g. &quot;a&quot;, &quot;b&quot;, &quot;c&quot; ...&lt;/p&gt;
&lt;p&gt;Unfortunately the 7771th iteration generates the prefix string &quot;xml&quot;, which is illegal to use and is rejected in &lt;code&gt;clojure.data.xml.pu-map/assoc!&lt;/code&gt; by the check in &lt;code&gt;(name/legal-xmlns-binding! prefix uri)&lt;/code&gt;, causing the above quoted exception. The same problem will happen later for &quot;xmlns&quot;.&lt;/p&gt;
&lt;p&gt;An easy workaround is to not do the checks in case the uri is blank.&lt;/p&gt;
</description>
<category>data.xml</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12688/clojure-data-xml-aggregate-generates-invalid-xmlns-prefixes</guid>
<pubDate>Wed, 22 Feb 2023 22:37:19 +0000</pubDate>
</item>
<item>
<title>clojure/data.xml tests fail on JDK 17</title>
<link>https://ask.clojure.org/index.php/11546/clojure-data-xml-tests-fail-on-jdk-17</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;The clojure/data.xml test suite fails to run on JDK 17 with the following error&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ lein test
Exception in thread &quot;main&quot; Syntax error compiling at (clojure/data/xml/cljs_repls.clj:11:5).
	at clojure.lang.Compiler.analyze(Compiler.java:6808)
	...
	at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: No such var: repl-nh/eval-resource
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.Compiler.resolveIn(Compiler.java:7387)
	at clojure.lang.Compiler.resolve(Compiler.java:7357)
	at clojure.lang.Compiler.analyzeSymbol(Compiler.java:7318)
	at clojure.lang.Compiler.analyze(Compiler.java:6768)
	... 67 more
Tests failed.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is because the Clojurescript tests run on top of the Nashorn JS engine, but the latter has been removed from JDK 15 onwards. &lt;/p&gt;
&lt;p&gt;Are there any plans to run the tests directly from Clojurescript, perhaps as core.async does it with deps.edn? Happy to have a look if so and you are open to PRs.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Test</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11546/clojure-data-xml-tests-fail-on-jdk-17</guid>
<pubDate>Sun, 06 Feb 2022 18:20:42 +0000</pubDate>
</item>
</channel>
</rss>