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.

Nicolas M.
  • 789
  • 1
  • 13
  • 23

1 Answers1

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.

Michał Marczyk
  • 83,634
  • 13
  • 201
  • 212
  • 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: http://stackoverflow.com/questions/18094278/clojure-leining-repl-outofmemoryerror-java-heap-space – Nicolas M. Aug 07 '13 at 03:45
  • I wonder though, how does the error message come to explain the problem? – matanster Oct 28 '16 at 12:24