Created
February 12, 2014 20:19
-
-
Save wjlroe/8963743 to your computer and use it in GitHub Desktop.
How to parse complicated XML with no Internet requirements and no entity nonsense
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 flaming-pidgeon.core | |
(:require | |
[clojure.xml :as xml])) | |
(defn startparse-sax-non-validating | |
[s ch] | |
(.. (doto (. javax.xml.parsers.SAXParserFactory (newInstance)) | |
(.setValidating false) | |
(.setFeature "http://apache.org/xml/features/nonvalidating/load-dtd-grammar" false) | |
(.setFeature "http://apache.org/xml/features/nonvalidating/load-external-dtd" false) | |
(.setFeature "http://xml.org/sax/features/validation" false) | |
(.setFeature "http://xml.org/sax/features/external-general-entities" false) | |
(.setFeature "http://xml.org/sax/features/external-parameter-entities" false)) | |
(newSAXParser) | |
(parse s ch))) | |
(doseq [node (xml-seq (xml/parse "somefile.xml" startparse-sax-non-validating))] | |
(println (:tag node))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment