Why won't clojure.data.xml round-trip my svg file?

totopsy

New Member
Here is a file yo.svg:\[code\]<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50" stroke="black" stroke-width="2" fill="red" /></svg>\[/code\]Both Firefox and Chrome render it as a red circle with a black border. (I don't know what other browsers do though).Below is some clojure code (version 1.4), which takes that, writes it out to yo.svg, parses it, re-encodes it, and writes the result out to yo2.svg, which looks like:\[code\]<?xml version="1.0" encoding="UTF-8"?><svg width="200" height="200"> <circle cx="50" cy="50" r="50" stroke="black" stroke-width="2" fill="red"/></svg>\[/code\]Obviously clojure is making changes. Neither browser will render yo2.svg.I am figuring that I am doing something wrong, but considerable research has just left me bewildered:I'm wondering why clojure is making these changes, and whether I should ignore clojure.data.xml and just generate xml by hand, or use clojure.data.xml to do the middle bit and write my own headers. Is svg even a type of xml?Here is my clojure program:\[code\](require 'clojure.data.xml)(let [ xml-picture "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"50\" cy=\"50\" r=\"50\" stroke=\"black\" stroke-width=\"2\" fill=\"red\" /></svg>" round-trip-picture (clojure.data.xml/indent-str (clojure.data.xml/parse-str xml-picture))] (spit "yo.svg" xml-picture) (spit "yo2.svg" round-trip-picture) (println xml-picture) (println "------------------") (println round-trip-picture))\[/code\]
 
Back
Top