Last active
April 2, 2019 19:45
-
-
Save mangosmoothie/a2b25025f5cf3484f30de40bd7d05042 to your computer and use it in GitHub Desktop.
remove keys with nil value from clojure.xml parsed xml file
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
;; remove keys with nil value from a data structure created by parsing an xml file with clojure.xml | |
;; to do this you first must convert the clojure.xml elements to regular maps since they are created | |
;; as structs and thus will not allow you to remove keys | |
(require '[com.rpl.specter :as r] '[clojure.xml :as xml]) | |
(def ALL-ELEMENTS | |
(r/recursive-path | |
[] p | |
(r/if-path :content | |
(r/continue-then-stay [:content r/ALL p]) | |
r/STAY))) | |
(def NIL-VALS | |
(r/recursive-path | |
[] p | |
(r/if-path map? | |
[r/MAP-VALS p] | |
(r/if-path vector? | |
[r/ALL p] | |
(r/if-path nil? r/STAY))))) | |
(def note-xsd | |
(->> (xml/parse "note.xsd") | |
(r/transform [ALL-ELEMENTS] #(into {} %)) | |
(r/setval [NIL-VALS] r/NONE))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment