Reading XML data into Incanter datasets
One of the most popular formats for data is XML. Some people love it, some hate it. But almost everyone has to deal with it at some point. Clojure can use Java's XML libraries, but it also has its own package, which provides a more natural way of working with XML in Clojure.
First, include these dependencies in our Leiningen
:dependencies [[org.clojure/clojure "1.4.0"] [incanter/incanter-core "1.4.1"]]
Use these libraries in our REPL interpreter or program:
(use 'incanter.core 'clojure.xml '[clojure.zip :exclude [next replace remove]])
And find a data file. I have a file named
data/small-sample.xml that looks like the following:
<?xml version="1.0" encoding="utf-8"?> <data> <person> ...