1.3.0 permalink Arrow_down_16x16

xml-zip

clojure.zip

  • (xml-zip root)
Returns a zipper for xml elements (as from xml/parse),
given a root element

2 Examples top

  • (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}]
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/zip.clj:53 top

(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))
Vars in clojure.zip/xml-zip:
Used in 0 other vars

Comments top

No comments for xml-zip. Log in to add a comment.