                 :X (if mark "X" " ")
                 :D3 ""
                 :A ""
-                :B "Awesome4"}))
+                :B ""}))
 
 (defn make-mark-list-node [marks]
   (xml/element :MarkList

;; Provides useful Timbre aliases in this ns
(log/refer-timbre)

(defn get-zip []
  (let [test-file
        (slurp (str "test/tango/examples/real-example-kungsor.xml"))]
    (zip/xml-zip
      (clojure.xml/parse (java.io.ByteArrayInputStream. (.getBytes test-file))))))

(defn get-xml []
  (let [test-file
        (slurp (str "test/tango/examples/real-example-kungsor.xml"))]
    (clojure.xml/parse (java.io.ByteArrayInputStream. (.getBytes test-file)))))

;(def zipper (get-zip))
;
;(zx/attr (first (zx/xml-> zipper :CompData)) :Place)
;
;(zx/xml-> zipper :Class)
;
;(zx/attr (first (zx/xml-> zipper :ClassList :Class)) :Name)
;
;(zx/xml-> zipper :ClassList :Class)
;
;(first (zx/xml-> zipper :ClassList :Class))
;(xml/emit-str (xml/element :Result {:Seq 0}))
;; Producera ett <Result> i <Results>

;(def zipper (zip/xml-zip (get-xml)))
;
;(defn tree-edit
;  "Take a zipper, a function that matches a pattern in the tree,
;   and a function that edits the current location in the tree.  Examine the tree
;   nodes in depth-first order, determine whether the matcher matches, and if so
;   apply the editor."
;  [zipper matcher editor]
;  (loop [loc zipper]
;    (if (zip/end? loc)
;      (zip/root loc)
;      (if-let [matcher-result (matcher loc)]
;        (let [new-loc (zip/edit loc editor)]
;          (if (not (= (zip/node new-loc) (zip/node loc)))
;            (recur (zip/next new-loc))))
;        (recur (zip/next loc))))))
;
;;; match predicate, all book tags
;(defn match-book? [loc]
;  (let [tag (:tag (zip/node loc))]
;    ;; true if tag is of type <path>
;    (= :Class tag)))
;
;(def test-names
;  {"Hiphop Singel Guld U" "XXXXXXXXXXXXXXXXX"})
;
;;; edit function
;(defn editor [node]
;  (let [id (-> node :attrs :Name)
;        new-content (conj
;                      (:content node)
;                      (xml/element :price {} "XX"               ;(get test-names id id)
;                                   ))]
;    (assoc-in node [:content] new-content)))
;
;(def edited (tree-edit zipper match-book? editor))
;
;edited
;(xml/indent-str
;  edited)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def raw-xml (get-xml))

;; TODO - kolla om results finns pa icke startade
(let [content (get-in raw-xml [:content])
      class-list (nth content 2)
      class-to-fix (first (filter #(= "Hiphop Singel Brons B1" (:Name (:attrs %))) (:content class-list)))
      class-results (first (filter #(= :Results (:tag %)) (:content class-to-fix)))
      new-results (conj (:content class-results) {:tag     :Result
                                                  :attrs   {:hej "Marten"}
                                                  :content nil})]

  ;new-results
  (assoc class-results :content new-results)
  )

(def new-stuff
  (clojure.walk/postwalk
    (fn [form]
      (cond
        (= (:tag form) :Class) (if (= (:Name (:attrs form))
                                      "Hiphop Singel Brons B1")
                                 {:tag     :Class
                                  :attrs   {:Name "Changed Class"}
                                  :content nil}
                                 form)
        :else form))
    raw-xml))

(spit "export3.xml" (with-out-str (clojure.xml/emit new-stuff)))


(def raw-xml-2
  (xml/parse (java.io.FileInputStream. "test/tango/examples/real-example.xml")))

(def class-results [{:class-name "Disco Freestyle B-klass J Po"
                     :result {:round "S"

                                 ;(xml/element :Class {:Name "Changed Class"})
                                 form)
        :else form))
    xml-data))

(defn smoke-test []
  (let [in-xml (get-xml-from-file "test/tango/examples/real-example.xml")
        out-xml (add-results-to-dp-xml in-xml (first class-results))]
    (spit "export5.xml" (xml/emit-str out-xml))))

(smoke-test)

;; API
(defn export-results [stuff]
  (log/info (str "Export Results with " stuff)))
