9292 <foo><bar><baz>The baz value</baz></bar></foo>")]
9393 (xml/parse input-xml))
9494
95- #clojure.data.xml.Element{:tag :foo,
96- :attrs {},
97- :content (#clojure.data.xml.Element{:tag :bar,
98- :attrs {},
99- :content (#clojure.data.xml.Element{:tag :baz,
100- :attrs {},
101- :content ("The baz value")})})}
95+ #xml/element{:tag :foo,
96+ :content [#xml/element{:tag :bar,
97+ :content [#xml/element{:tag :baz,
98+ :content ["The baz value"]}]}]}
10299
103100The data is returned as defrecords and can be manipulated using the
104101normal clojure data structure functions. Additional parsing options
105102can be passed via key pairs:
106103
107104 (xml/parse-str "<a><![CDATA[\nfoo bar\n]]><![CDATA[\nbaz\n]]></a>" :coalescing false)
108- #clojure.data. xml.Element {:tag :a, :attrs {}, : content ( "\nfoo bar\n" "\nbaz\n") }
105+ #xml/element {:tag :a, :content [ "\nfoo bar\n" "\nbaz\n"] }
109106
110107XML elements can be created using the typical defrecord constructor
111108functions or the element function used below or just a plain map with : tag : attrs : content keys, and written using a
@@ -134,7 +131,7 @@ Comments and CDATA can also be emitted as an S-expression with the special tag n
134131
135132 (= (xml/element :tag {:attr "value"}
136133 (xml/element :body {} (xml/cdata "not parsed <stuff")))
137- (xml/sexp-as-element [:tag {:attr "value"} [:body {} [:-cdata "not parsed <stuff"]]]
134+ (xml/sexp-as-element [:tag {:attr "value"} [:body {} [:-cdata "not parsed <stuff"]]]))
138135 ;;-> true
139136
140137XML can be "round tripped" through the library:
@@ -147,7 +144,7 @@ XML can be "round tripped" through the library:
147144 (with-open [input (java.io.FileInputStream. "/tmp/foo.xml")]
148145 (xml/parse input)))
149146
150- #clojure.data. xml.Element {:tag :foo, :attrs {:foo-attr "foo value"}...}
147+ #xml/element {:tag :foo, :attrs {:foo-attr "foo value"}...}
151148
152149There are also some string based functions that are useful for
153150debugging.
@@ -186,10 +183,10 @@ CDATA can be emitted:
186183
187184But will be read as regular character data:
188185
189- (xml/parse-str (xml/emit-str (element :foo {}
186+ (xml/parse-str (xml/emit-str (xml/ element :foo {}
190187 (xml/cdata "<non><escaped><info><here>"))))
191188
192- #clojure.data. xml.Element {:tag :foo, :attrs {}, : content ( "<non><escaped><info><here>") }
189+ #xml/element {:tag :foo, :content [ "<non><escaped><info><here>"] }
193190
194191Comments can also be emitted:
195192
@@ -219,9 +216,7 @@ Below is an example of parsing an XHTML document:
219216 (xml/parse-str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
220217 <foo:html xmlns:foo=\"http://www.w3.org/1999/xhtml\"/>")
221218
222- #...Element{:tag :xmlns.http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml/html,
223- :attrs {},
224- :content ()}
219+ #xml/element{:tag :xmlns.http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml/html}
225220
226221Emitting namespaced XML is usually done by using ` alias-uri ` in combination with clojure's built-in ` ::kw-ns/shorthands ` :
227222
@@ -238,7 +233,7 @@ Emitting namespaced XML is usually done by using `alias-uri` in combination with
238233
239234It is also allowable to use ` javax.xml.namespace.QName ` instances, as well as strings with the informal ` {ns}n ` encoding.
240235
241- (xml/emit-str {:tag (qname "http://www.w3.org/1999/xhtml" "html")})
236+ (xml/emit-str {:tag (xml/ qname "http://www.w3.org/1999/xhtml" "html")})
242237 (xml/emit-str {:tag "{http://www.w3.org/1999/xhtml}html"})
243238
244239 <?xml version=\"1.0\" encoding=\"UTF-8\"?><a:html xmlns:a=\"http://www.w3.org/1999/xhtml\"></a:html>
@@ -297,7 +292,7 @@ By default the parser attaches location information as element meta,
297292 (deftest test-location-meta
298293 (let [input "<a><b/>\n<b/></a>"
299294 location-meta (comp :clojure.data.xml/location-info meta)]
300- (is (= 1 (-> input xml/parse-str location-meta :line-number)))
295+ (is (= 1 (-> input xml/parse-str location-meta :line-number)))))
301296
302297To elide location information, pass ` :location-info false ` to the parser:
303298
0 commit comments