Skip to content

Instantly share code, notes, and snippets.

@rmuslimov
Last active February 19, 2016 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmuslimov/9fccefd7b5528234ed07 to your computer and use it in GitHub Desktop.
Save rmuslimov/9fccefd7b5528234ed07 to your computer and use it in GitHub Desktop.
Clojure version of xml parsing
(ns logprocessor.core
(:require [clojure.java.io :as io]
[clojure.zip :as zip]
[clojure.data.xml :as xml]
[clojure.data.zip.xml :as zx])
(:gen-class))
(def store "/Users/rmuslimov/projects/logs/d=12")
(defn get-zipper
"Get zipper from FileObject instance."
[filename]
(-> filename io/input-stream xml/parse zip/xml-zip))
(defn get-xml-method-name
[zipper]
"Just test mode only get example xml file."
(let [body (zx/xml1-> zipper :Body)]
(-> body zip/down zip/node :tag)))
(defn get-xml-method-name2
[zipper]
(-> zipper zip/down zip/right zip/down zip/down :tag))
(defn get-xml-method-name3
[zipper]
(type zipper))
(defn parse-all
[]
(time
(count
(map
#(-> % get-zipper get-xml-method-name2)
(-> store io/file file-seq rest)))))
(defn -main
""
[& args]
(dotimes [n 10] (parse-all)))
;; (-main)
;; (parse-all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment