I have a leiningen project with [org.clojure/data.xml "0.0.7"] as a dependency and an xml file in data/data-sample.xml
That works:
(require '[clojure.xml :as xml])
(xml/parse "data/small-sample.xml")
It returns:
{:tag :data, :attrs nil, :content [{:tag :person, :attrs nil, :content [{:tag :given-name, :attrs nil, :content ["Gomez"]} {:tag :surname, :attrs nil, :content ["Addams"]} {:tag :relation, :attrs nil, :content ["father"]}]} {:tag :person, :attrs nil, :content [{:tag :given-name, :attrs nil, :content ["Morticia"]}...
That doesn't work:
(require '[clojure.data.xml :as data.xml])
(data.xml/parse "data/small-sample.xml")
It returns:
IllegalArgumentException No matching method found: createXMLStreamReader for class com.sun.xml.internal.stream.XMLInputFactoryImpl clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
What am I doing wrong? Thanks.
As explained in its docstring,
clojure.data.xml/parse
accepts anInputStream
orReader
, so that's what you need to provide:Note that
io/reader
attempts to treat strings as URIs as a first guess, then as local file names. You can useio/file
if you want to be explicit about dealing with a file ((io/reader (io/file ...))
). There's alsoio/resource
for looking things up on the classpath.