Last active
February 19, 2016 07:55
-
-
Save rmuslimov/9fccefd7b5528234ed07 to your computer and use it in GitHub Desktop.
Clojure version of xml parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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