I have some code, that parses out soap data with the use of zippers. When I format it like so it works as expected for me
(defn parse-data
[raw-data]
(let [soap-data (:body raw-data)
soap-envelope (zip/xml-zip
(xml/parse
(java.io.ByteArrayInputStream. (.getBytes (str soap-data) "UTF-8"))))]
(pprint (xml-z/xml-> soap-envelope :soap:Envelope :soap:Body :Tag1 :Tag2))))
It prints out the expected result. But when I move the XML parsing to the let statement it fails to compile, with the following error (I've triple checked my brackets match up)
RuntimeException EOF while reading, starting at line 3 clojure.lang.Util.runtimeException (Util.java:221)
jcode.oc-drift.aquisition=> (pprint result-data)))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: result-data in this context, compiling:(/tmp/form-init6714472131112461091.clj:1:1)
RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)
jcode.oc-drift.aquisition=>
The code was changed to put the xml-z/xml-> call into the let statement, as follows
(defn parse-data
[raw-data]
(let [soap-data (:body raw-data)
soap-envelope (zip/xml-zip
(xml/parse
(java.io.ByteArrayInputStream. (.getBytes (str soap-data) "UTF-8"))))
result-data (xml-z/xml-> soap-envelope :soap:Envelope :soap:Body :GetNextTripsForStopResponse :GetNextTripsForStopResult)]
(pprint result-data)))
Is this a bug with the let form, or am I missing something about the behaviour of xml-> functionality?
The full code file with the non-working function call:
src/hello/core.clj:
(ns hello.core
(:require [clj-http.client :as http-client]
[clojure.zip :as zip]
[clojure.xml :as xml]
[clojure.data.xml :as xml-data]
[clojure.data.zip.xml :as xml-z]))
(use 'clojure.pprint)
(def app-id "redacted")
(def api-key "redacted")
(def post-data {:apiKey api-key :appID app-id})
(defn get-data
[post-data function]
"function is a string with the api function to be called"
(let [url (str "redacted" function)]
(http-client/post url {:form-params post-data})))
(defn parse-data
[raw-data]
(let [soap-data (:body raw-data)
soap-envelope (zip/xml-zip
(xml/parse
(java.io.ByteArrayInputStream. (.getBytes (str soap-data) "UTF-8"))))
result-data (xml-z/xml-> soap-envelope :soap:Envelope :soap:Body :GetNextTripsForStopResponse :GetNextTripsForStopResult)]
(pprint result-data)))
project.clj:
(defproject hello "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"}
:main hello.core
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/data.xml "0.0.8"]
[org.clojure/data.zip "0.1.2"]
[clj-http "2.2.0"]])