Created
December 13, 2015 14:11
-
-
Save senior/3707106a589bf29231bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- qname-reader [form] | |
(let [[local-part uri] form | |
prefix-index (.indexOf local-part ":")] | |
(if (= -1 prefix-index) | |
(make-qname uri | |
local-part | |
"") | |
(make-qname uri | |
(subs local-part (inc prefix-index)) | |
(subs local-part 0 prefix-index))))) | |
(defmethod print-method javax.xml.namespace.QName [^javax.xml.namespace.QName qname ^java.io.Writer w] | |
(.write w (str "#javax.xml.namespace.QName [\"" | |
(let [prefix (.getPrefix qname)] | |
(when (and prefix (not= prefix "")) | |
(str prefix ":"))) | |
(qname-local qname) | |
"\" \"" | |
(qname-uri qname) | |
"\"]"))) | |
(defmethod print-dup javax.xml.namespace.QName [o w] | |
(print-method o w)) | |
(clojure.pprint/pprint (parse-str "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:foo=\"http://www.w3.org/2000/svg2\"> | |
<circle id=\"greencircle\" cx=\"30\" cy=\"30\" r=\"30\" fill=\"green\" /> | |
<foo:circle id=\"greencircle\" cx=\"30\" cy=\"30\" r=\"30\" fill=\"green\" /> | |
</svg>")) | |
{:tag #javax.xml.namespace.QName ["svg" "http://www.w3.org/2000/svg"], | |
:attrs {}, | |
:content | |
({:tag | |
#javax.xml.namespace.QName ["circle" "http://www.w3.org/2000/svg"], | |
:attrs | |
{:id "greencircle", :cx "30", :cy "30", :r "30", :fill "green"}, | |
:content ()} | |
{:tag | |
#javax.xml.namespace.QName ["foo:circle" "http://www.w3.org/2000/svg2"], | |
:attrs | |
{:id "greencircle", :cx "30", :cy "30", :r "30", :fill "green"}, | |
:content ()})} | |
I also thought about something more compact: | |
{:tag #javax.xml.namespace.QName "{http://www.w3.org/2000/svg}circle", | |
:attrs {}, | |
:content | |
({:tag | |
#javax.xml.namespace.QName "{http://www.w3.org/2000/svg}circle", | |
:attrs | |
{:id "greencircle", :cx "30", :cy "30", :r "30", :fill "green"}, | |
:content ()} | |
{:tag | |
#javax.xml.namespace.QName "{foo|http://www.w3.org/2000/svg2}circle", | |
:attrs | |
{:id "greencircle", :cx "30", :cy "30", :r "30", :fill "green"}, | |
:content ()})} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment