Changes for clojure.xml/parse

rafmagana on Tue, 22 Jul 2014
(require '[clojure.xml :as xml]
         '[clojure.zip :as zip])

;;convenience function, first seen at nakkaya.com later in clj.zip src
(defn zip-str [s]
  (zip/xml-zip 
      (xml/parse (java.io.ByteArrayInputStream. (.getBytes s)))
  )
)

;;parse from xml-strings to internal xml representation
user=> (zip-str "<a href='nakkaya.com'/>")
[{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]

;;root can be rendered with xml/emit-element
user=> (xml/emit-element (zip/root [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]))
<a href='nakkaya.com'/>

;;printed (to assure it's not lazy and for performance), can be caught to string variable with with-out-str
Lowgain on Mon, 02 Dec 2013
(require '[clojure.xml :as xml]
         '[clojure.zip :as zip])

;;convenience function, first seen at nakkaya.com later in clj.zip src
(defn zip-str [s]
  (zip/xml-zip (xml/parse (java.io.ByteArrayInputStream. (.getBytes s)))))

;;parse from xml-strings to internal xml representation
(zip-str "<a href='nakkaya.com'/>")
=>
[{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]

;;root can be rendered with xml/emit-element
(xml/emit-element (zip/root [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]))
=>
<a href='nakkaya.com'/>
;;printed (to assure it's not lazy and for performance), can be caught to string variable with with-out-str





balamkej on Sun, 18 Mar 2012
(require '[clojure.xml :as xml]
         '[clojure.zip :as zip])

;;convenience function, first sawn at nakkaya.com later in clj.zip src
(defn zip-str [s]
  (zip/xml-zip (xml/parse (java.io.ByteArrayInputStream. (.getBytes s)))))

;;parse from xml-strings to internal xml representation
(zip-str "<a href='nakkaya.com'/>")
=>
[{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]

;;root can be rendered with xml/emit-element
(xml/emit-element (zip/root [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]))
=>
<a href='nakkaya.com'/>
;;printed (to assure it's not lazy and performance), can be catched to string variable with with-out-str





Claj on Thu, 22 Dec 2011
(require '[clojure.xml :as xml]
         '[clojure.zip :as zip])

;;convenience function, first sawn at nakkaya.com later in clj.zip src
(defn zip-str [s]
  (zip/xml-zip (xml/parse (java.io.ByteArrayInputStream. (.getBytes s)))))

;;parse from xml-strings to internal xml representation
(zip-str "<a href='nakkaya.com'/>")
=>
[{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]

;;root can be rendered with xml/emit-element
(emit-element (zip/root [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil]))
=>
<a href='nakkaya.com'/>
;;printed (to assure it's not lazy and performance), can be catched to string variable with with-out-str