2012-12-29 19 views
0

這裏是一個文件yo.svg爲什麼不會clojure.data.xml往返我的svg文件?

<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> 

Firefox和Chrome瀏覽器呈現爲一個紅圈,並帶有黑色邊框。 (我不知道其他瀏覽器做了什麼)。

下面是一些Clojure的代碼(1.4版),這需要的是,把它寫到yo.svg,解析它,再對其進行編碼,然後將結果寫出來yo2.svg,看起來如:

<?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> 

clojure顯然正在進行更改。瀏覽器都不會呈現yo2.svg

我盤算,我做錯了什麼,但相當多的研究纔剛剛給我留下了一臉茫然:

我不知道爲什麼Clojure是做了這些改變,以及是否我應該忽略clojure.data.xml和公正手工生成xml,或者使用clojure.data.xml做中間位並寫我自己的頭文件。是svg甚至是一種類型的XML?

這裏是我的Clojure程序:

(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)) 

回答

3

你想要的是:

(clojure.data.xml/parse-str xml-picture :namespace-aware false) 

這樣的解析器將像對待其他屬性的命名空間標記。否則,它不會在解析樹中包含xmlns標籤。

+0

這只是奇怪。還有什麼其他奇怪的技巧可能會讓我背後呢? –

+1

檢出:http://clojure.github.com/data.xml/#clojure.data.xml/parse-str和http://docstore.mik.ua/orelly/xml/xmlnut/ch04_03.htm –

相關問題