Returns a zipper for xml elements (as from xml/parse),
given a root element
(def xmlzipper (clojure.zip/xml-zip (clojure.xml/parse "resources/somedata.xml"))) ;;make a zippper pointing at the children to the topnode in somedata.xml (clojure.zip/children xmlzipper)
(require '[clojure.zip :as z])
user=> (z/right
(z/down
(z/xml-zip
{:tag :root :content [{:tag :any :content ["foo" "bar"]} "bar"]})))
["bar" {:l [{:content ["foo" "bar"], :tag :any}], :pnodes [{:content [{:content ["foo" "bar"], :tag :any} "bar"], :tag :root}], :ppath nil, :r nil}]
;; The above can also be written like this:
user=> (->
(z/xml-zip {:tag :root :content [{:tag :any :content ["foo" "bar"]} "bar"]})
z/down z/right)
["bar" {:l [{:content ["foo" "bar"], :tag :any}], :pnodes [{:content [{:content ["foo" "bar"], :tag :any} "bar"], :tag :root}], :ppath nil, :r nil}]
(defn xml-zip
"Returns a zipper for xml elements (as from xml/parse),
given a root element"
{:added "1.0"}
[root]
(zipper (complement string?)
(comp seq :content)
(fn [node children]
(assoc node :content (and children (apply vector children))))
root))
Comments top
No comments for xml-zip. Log in to add a comment.