Database Reference
In-Depth Information
Reading XML data into Incanter datasets
One of the most popular formats for data is XML. Some people love it, while some hate it.
However, almost everyone has to deal with it at some point. While Clojure can use Java's
XML libraries, it also has its own package which provides a more natural way to work with
XML in Clojure.
Getting ready
First, include these dependencies in your Leiningen
project.clj
ile:
(defproject getting-data "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]])
Use these libraries in your REPL or program:
(require '[incanter.core :as i]
'[clojure.xml :as xml]
'[clojure.zip :as zip])
Then, ind a data ile. I visited the website for the Open Data Catalog for Washington, D.C.
I moved this ile to
data/crime_incidents_2013_plain.xml
. This is how the contents
of the ile look:
<?xml version="1.0" encoding="iso-8859-1"?>
<dcst:ReportedCrimes
xmlns:dcst="http://dc.gov/dcstat/types/1.0/">
<dcst:ReportedCrime
xmlns:dcst="http://dc.gov/dcstat/types/1.0/">
<dcst:ccn><![CDATA[04104147]]></dcst:ccn>
<dcst:reportdatetime>
2013-04-16T00:00:00-04:00
</dcst:reportdatetime>
…