Changes for clojure.xml/element

Claj on Thu, 22 Dec 2011
(use 'clojure.zip)

;;using our old friend struct for performance in maps 
(struct element :httplink {:href "http://clojure.org"} nil)
=>
{:tag   :httplink, 
 :attrs {:href "http://clojure.org"}, 
 :content nil}

;;these elements can be output to ordinary xml strings with emit-element
(emit-element (struct element :httplink {:href "http://clojure.org"} nil))
=>
<httplink href='http://clojure.org'/>
;;this is printed - can be catched with macro with-out-str

;;make hierarchies:
(struct element :parent {:name "Barbara"} 
  [(struct element :children {:name "Gina"} nil) 
   (struct element :children {:name "John"} nil)])
=>
{:tag :parent, :attrs {:name "Barbara"}, :content 
   [{:tag :children, :attrs {:name "Gina"}, :content nil} 
    {:tag :children, :attrs {:name "John"}, :content nil}]}

;;which can be emit-elemented as well

(emit-element {:tag :parent, :attrs {:name "Barbara"}, :content [{:tag :children, :attrs {:name "Gina"}, :content nil} {:tag :children, :attrs {:name "John"}, :content nil}]})
=>
<parent name='Barbara'>
 <children name='Gina'/>
 <children name='John'/>
</parent>
Claj on Thu, 22 Dec 2011
(use 'clojure.zip)

;;using our old friend struct for performance in maps 
(struct element :httplink {:href "http://clojure.org"} nil)
=>
{:tag   :httplink, 
 :attrs {:href "http://clojure.org"}, 
 :content nil}

;;these elements can be output to ordinary xml strings with emit-element
(emit-element (struct element :httplink {:href "http://clojure.org"} nil))
=>
<httplink href='http://clojure.org'/>

;;make hierarchies:
(struct element :parent {:name "Barbara"} 
  [(struct element :children {:name "Gina"} nil) 
   (struct element :children {:name "John"} nil)])
=>
{:tag :parent, :attrs {:name "Barbara"}, :content 
   [{:tag :children, :attrs {:name "Gina"}, :content nil} 
    {:tag :children, :attrs {:name "John"}, :content nil}]}

;;which can be emit-elemented as well

(emit-element {:tag :parent, :attrs {:name "Barbara"}, :content [{:tag :children, :attrs {:name "Gina"}, :content nil} {:tag :children, :attrs {:name "John"}, :content nil}]})
=>
<parent name='Barbara'>
 <children name='Gina'/>
 <children name='John'/>
</parent>
Claj on Thu, 22 Dec 2011
(use 'clojure.zip)

;;using the old friend struct
(struct element :httplink {:href "http://clojure.org"} nil)
=>
{:tag   :httplink, 
 :attrs {:href "http://clojure.org"}, 
 :content nil}

;;these elements can be output to ordinary xml strings with emit-element
(emit-element (struct element :httplink {:href "http://clojure.org"} nil))
=>
<httplink href='http://clojure.org'/>

;;make hierarchies:
(struct element :parent {:name "Barbara"} 
  [(struct element :children {:name "Gina"} nil) 
   (struct element :children {:name "John"} nil)])
=>
{:tag :parent, :attrs {:name "Barbara"}, :content 
   [{:tag :children, :attrs {:name "Gina"}, :content nil} 
    {:tag :children, :attrs {:name "John"}, :content nil}]}

;;which can be emit-elemented as well

(emit-element {:tag :parent, :attrs {:name "Barbara"}, :content [{:tag :children, :attrs {:name "Gina"}, :content nil} {:tag :children, :attrs {:name "John"}, :content nil}]})
=>
<parent name='Barbara'>
 <children name='Gina'/>
 <children name='John'/>
</parent>

;;also check up struct-map for more efficient declaring of the children.