我正在关注this article进行XML解析。它有一个示例代码,当我在REPL中播放时,它对我不起作用:
(require '[clojure.data.zip.xml :as zip-xml])
它引发了以下错误:FileNotFoundException Could not locate clojure/data/zip/xml__init.class or clojure/data/zip/xml.clj on classpath
我正在使用leiningen进行项目,并在项目中定义了以下依赖项:
[org.clojure/clojure "1.5.1"]
[org.clojure/data.zip "0.1.1"]
关于问题的任何想法?
答案 0 :(得分:1)
从项目布局到需要重启nrepl可能存在一些问题。为了解决这个问题,这是一个可以测试的工作项目:
git clone git@github.com:thearthur/zip-xml-example.git
project.clj:
(defproject zip-example "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/data.zip "0.1.1"]])
core.clj:
(ns zip-example.core
(:require [clojure.data.zip.xml :as zip-xml]
[clojure.zip :as zip]
[clojure.xml :as xml]
[clojure.pprint :refer [pprint]]))
(def xml
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<!-- <!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN \" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd \"> -->
<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">
<head>
<meta type=\"title \">Your File!</meta>
<meta type=\"tag \">Example</meta>
</head>
<file poster=\"Joe Bloggs <bloggs@nowhere.example>\" date=\"1071674882\" subject=\"Here's your file! abc-mr2a.r01 (1/2)\">
<groups>
<group>alt.binaries.newzbin</group>
<group>alt.binaries.mojo</group>
</groups>
<segments>
<segment bytes= \"102394\" number= \"1\">123456789abcdef@news.newzbin.com</segment>
<segment bytes= \"4501\" number= \"2\">987654321fedbca@news.newzbin.com</segment>
</segments>
</file>
</nzb>")
(spit "test.xml" xml)
(def parsed-xml (zip/xml-zip (xml/parse "test.xml")))
(pprint (zip-xml/xml-> parsed-xml :head :meta))