Some Practical Clojure Examples
← prev | next →     Top-level ToC     /xml.html     (printable version)

XML file:

<main strength="10">
    <thing size="1" color="green">leaf</thing>
    <thing size="2" color="red">tomato</thing>
</main>

In your code:

(require '[clojure.xml :as xml]
         '[clojure.java.io :as io])

(def data (xml/parse (io/file input-filename)))
(prn data)

Output:

{:tag :main,
 :attrs {:strength "10"},
 :content [{:tag :thing,
            :attrs {:size "1", :color "green"},
            :content ["leaf"]}
           {:tag :thing,
            :attrs {:size "2", :color "red"},
            :content ["tomato"]}]}