1.3.0 permalink Arrow_down_16x16

xml-seq

clojure.core

  • (xml-seq root)
A tree seq on the xml elements as per xml/parse

2 Examples top

  • ;; data.xml from https://github.com/clojure/data.xml/
    (use '[clojure.data.xml :only [parse-str]])
    
    user=> (let [xml-text "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                          <foo key=\"val\">1<bar>2</bar>3</foo>"]
             (let [root (parse-str xml-text)]
               (xml-seq root)))
    
    ({:tag :foo,                                                   
      :attrs {:key "val"},                                         
      :content ("1" {:tag :bar, :attrs {}, :content ("2")} "3")}   
     "1"                                                           
     {:tag :bar, :attrs {}, :content ("2")}                        
     "2"                                                           
     "3")                                                          
    
  • (use '[clojure.xml :only [parse]])
    
    ;; clojure.xml/parse requires string to be ByteArrayInputStream
    user-> (let [xml-text "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
                          <foo key=\"val\">1<bar>2</bar>3</foo>"]
             (let [input (java.io.ByteArrayInputStream. 
                            (.getBytes xml-text))]
               (let [root (parse input)]
                 (xml-seq root))))
    
    ({:tag :foo,                                                   
      :attrs {:key "val"},                                         
      :content ("1" {:tag :bar, :attrs {}, :content ("2")} "3")}   
     "1"                                                           
     {:tag :bar, :attrs {}, :content ("2")}                        
     "2"                                                           
     "3")
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4364 top

(defn xml-seq
  "A tree seq on the xml elements as per xml/parse"
  {:added "1.0"
   :static true}
  [root]
    (tree-seq
     (complement string?)
     (comp seq :content)
     root))
Vars in clojure.core/xml-seq:
Used in 0 other vars

Comments top

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