1

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.

1 Answer 1

4

As explained in its docstring, clojure.data.xml/parse accepts an InputStream or Reader, so that's what you need to provide:

(require '[clojure.data.xml :as xml]
         '[clojure.java.io :as io])

(xml/parse (io/reader "data/small-sample.xml"))

Note that io/reader attempts to treat strings as URIs as a first guess, then as local file names. You can use io/file if you want to be explicit about dealing with a file ((io/reader (io/file ...))). There's also io/resource for looking things up on the classpath.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! Somehow, I expected them to behave the same way. I opened a new issue that I am having as a follow up to this here: stackoverflow.com/questions/18094278/…
I wonder though, how does the error message come to explain the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.