You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cookbooks/parsing_xml_with_zippers/index.html
+6-6
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ <h2>Parsing XML in Clojure</h2>
71
71
<p>This work is licensed under a <arel="license" href="https://creativecommons.org/licenses/by/3.0/">Creative Commons
72
72
Attribution 3.0 Unported License</a> (including images &
73
73
stylesheets). The source is available <ahref="https://github.com/clojure-doc/clojure-doc.github.io">on
74
-
Github</a>.</p><h2id="what-version-of-clojure-does-this-guide-cover">What Version of Clojure Does This Guide Cover?</h2><p>This guide covers Clojure 1.11 and Leiningen 2.x.</p><h2id="overview">Overview</h2><p>Try as you might, XML is difficult to avoid. This is particularly true
74
+
Github</a>.</p><h2id="what-version-of-clojure-does-this-guide-cover">What Version of Clojure Does This Guide Cover?</h2><p>This guide covers Clojure 1.12 and Leiningen 2.x.</p><h2id="overview">Overview</h2><p>Try as you might, XML is difficult to avoid. This is particularly true
75
75
in the Java ecosystem. This guide will show you how to parse XML with
76
76
the minimum amount of pain using the excellent tools available in
77
77
Clojure.</p><h2id="parsing-nzb-files">Parsing NZB files</h2><p>For the purpose of the tutorial I have chosen a simple and fairly well
@@ -242,14 +242,14 @@ <h2>Parsing XML in Clojure</h2>
</code></pre><h2id="how-to-invoke-java-methods">How to Invoke Java Methods</h2><h3id="instance-methods">Instance Methods</h3><p>Instance methods are invoked using the <code>.</code> special form:</p><pre><codeclass="clojure">(let [d (java.util.Date.)]
119
+
</code></pre><h2id="how-to-invoke-java-methods">How to Invoke Java Methods</h2><p>This guide does not cover type hints. See the official
120
+
<ahref="https://clojure.org/reference/java_interop#typehints">Java interop type hints</a>
121
+
and <ahref="https://clojure.org/reference/java_interop#paramtags">param-tags reference</a>
122
+
documentation for more details (since this area changed significantly in Clojure 1.12).</p><h3id="instance-methods">Instance Methods</h3><p>Instance methods are invoked using the <code>.</code> special form:</p><pre><codeclass="clojure">(let [d (java.util.Date.)]
120
123
(. d getTime)) ; ⇒ 1349819873183
121
124
</code></pre><p>Just like with object instantiation, it is much more common to see an alternative version:</p><pre><codeclass="clojure">(let [d (java.util.Date.)]
</code></pre><p>In Clojure 1.12, <code>SomeClass/.methodName</code> is a "function value" and can be treated like
133
136
a regular Clojure function:</p><pre><codeclass="clojure">(map Boolean/valueOf ["true" "false" "what?"])
134
137
;;⇒ (true false false)
135
-
</code></pre><h3id="chained-calls-with-the-double-dot-form">Chained Calls With The Double Dot Form</h3><p>It is possible to chain method calls using the <code>..</code> special form:</p><pre><codeclass="clojure">(.. (java.util.Date.) getTime toString) ; ⇒ "1693344712616"
138
+
</code></pre><blockquote><p>Note: Clojure 1.11 introduced <code>parse-boolean</code> but it is somewhat stricter than <code>Boolean/valueOf</code> and will return <code>nil</code> for strings it does not recognize, including <code>"TRUE"</code> and <code>"FALSE"</code> (which <code>Boolean/valueOf</code> does recognize).</p></blockquote><h3id="chained-calls-with-the-double-dot-form">Chained Calls With The Double Dot Form</h3><p>It is possible to chain method calls using the <code>..</code> special form:</p><pre><codeclass="clojure">(.. (java.util.Date.) getTime toString) ; ⇒ "1693344712616"
136
139
</code></pre><h3id="multiple-calls-on-the-same-object">Multiple Calls On the Same Object</h3><p>If you need to call several methods on the same (mutable) object, you
137
140
can use the <code>doto</code> macro:</p><pre><codeclass="clojure">(doto (java.util.Stack.)
</code></pre><p>In Clojure 1.12, you can <code>SomeClass/N</code> to get a class reference to an N-dimensional array of the class,
206
-
but prior to 1.12, you had to use <code>Class/forName</code> and the internal name of the array type:</p><tableclass="table-striped table-bordered table"><thead><tr><th>Internal JVM class name</th><th>Array of ? (type)</th><th>Clojure 1.12 type</th></tr></thead><tbody><tr><td><pre>"[S"</pre></td><td>short</td><td>short/1</td></tr><tr><td><pre>"[I"</pre></td><td>integer</td><td>integer/1</td></tr><tr><td><pre>"[J"</pre></td><td>long</td><td>long/1</td></tr><tr><td><pre>"[F"</pre></td><td>float</td><td>float/1</td></tr><tr><td><pre>"[D"</pre></td><td>double</td><td>double/1</td></tr><tr><td><pre>"[B"</pre></td><td>byte</td><td>byte/1</td></tr><tr><td><pre>"[C"</pre></td><td>char</td><td>char/1</td></tr><tr><td><pre>"[Z"</pre></td><td>boolean/1</td></tr></tbody></table><p>For convenience, Clojure has <code>*-array</code> functions for each of the above
209
+
but prior to 1.12, you had to use <code>Class/forName</code> and the internal name of the array type:</p><tableclass="table-striped table-bordered table"><thead><tr><th>Internal JVM class name</th><th>Array of ? (type)</th><th>Clojure 1.12 type</th></tr></thead><tbody><tr><td><pre>"[S"</pre></td><td>short</td><td>short/1</td></tr><tr><td><pre>"[I"</pre></td><td>integer</td><td>integer/1</td></tr><tr><td><pre>"[J"</pre></td><td>long</td><td>long/1</td></tr><tr><td><pre>"[F"</pre></td><td>float</td><td>float/1</td></tr><tr><td><pre>"[D"</pre></td><td>double</td><td>double/1</td></tr><tr><td><pre>"[B"</pre></td><td>byte</td><td>byte/1</td></tr><tr><td><pre>"[C"</pre></td><td>char</td><td>char/1</td></tr><tr><td><pre>"[Z"</pre></td><td>boolean</td><td>boolean/1</td></tr></tbody></table><p>For convenience, Clojure has <code>*-array</code> functions for each of the above
207
210
types that help you create an array of primitive values:</p><pre><codeclass="clojure">user=> (char-array [\h \e \l \l \o])
0 commit comments