I'm outputting a xml file from clojure using data.xml. I need to output the following line:
<use xlink:href="#whiskers" transform="scale(-1 1) translate(-140 0)" />
(We're drawing a cat in SVG).
Now, my try is something like:
(indent-str (element :use {:xlink:href "#whiskers",
:transform "scale(-1 1) translate(-140 0)"}))
This fails because :xlink:href "#whiwksers" is apparently interpreted as: :xlink , :href "#whiskers"
How do I create a clojure symbol to output "xlink:href" as a field for data.xml?
I have tried: (keyword "xlink:href")
still same error. Not sure what's going on.
I'm not sure there is an error here.
(def e (element :use {:xlink:href "#whiskers",
:transform "scale(-1 1) translate(-140 0)"}))
(println (emit-str e))
=> <?xml version="1.0" encoding="UTF-8"?><use xlink:href="#whiskers" transform="scale(-1 1) translate(-140 0)"></use>
The indent-str function has a problem though:
(println (indent-str e))
org.xml.sax.SAXParseException: The prefix "xlink" for attribute "xlink:href"
associated with an element type "use" is not bound.
So it appears clojure.data.xml is namespace aware. Let's try this:
(def e-the-sequel (element :use {:xmlns:xlink "http://testing",
:xlink:href "#whiskers",
:transform "scale(-1 1) translate(-140 0)"}))
(println (indent-str e-the-sequel))
=> <?xml version="1.0" encoding="UTF-8"?>
<use xmlns:xlink="http://testing" xlink:href="#whiskers"
transform="scale(-1 1) translate(-140 0)"/>
That's better. If anything, I guess you could argue that emit-str is wrong because it didn't throw an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With