Batik, SVG and weird javascript errors

I am using Clojure to generate SVG documents. To do this I use a library called lacij which in turn uses tikkba; a wrapper around the Apache Batik SVG generation library.

I added support for embedding javascript inside the SVG document (not the html) by manipulating the DOM as described here

The problem was that I was getting weird svg error “unknown language text/ecmascript”. As it turns out I was using the wrong xlink namespace and posted the answer on the above mentioned thread.

The code I wrote now is like this:

(defn build-svg-graph [graph]
(def new-graph(-> graph
(LALayout/layout :hierarchical)

(def element
(:xmldoc new-graph)
[:script {"xlink:href" "myscript.js" :type "text/ecmascript"}]

(Dom/append-child (Dom/document-element (:xmldoc new-graph)) element)

(Dom/spit-str (:xmldoc new-graph) :indent "yes")

Note that I needed to use xlink:href instead of src for embedding javascript refs in svg. src works in HTML not in SVG