可能有几个问题,从项目布局到需要重新启动 nrepl。为了解决这个问题,这里有一个可以测试的工作项目:
git clone git@github.com:thearthur/zip-xml-example.git
项目.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"]])
核心.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))