Skip to content

Instantly share code, notes, and snippets.

@wjlroe
Created February 12, 2014 20:19
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 wjlroe/8963743 to your computer and use it in GitHub Desktop.
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
(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