diff --git a/docs/libraries.md b/docs/libraries.md index 4065e65..c186820 100644 --- a/docs/libraries.md +++ b/docs/libraries.md @@ -57,6 +57,9 @@ e.g. the [ring-app example](https://github.com/jolt-lang/examples/tree/main/ring * [core.contracts](https://github.com/clojure/core.contracts) — programming by contract (`contract`/`with-constraints`/`provide`), over [core.unify](https://github.com/clojure/core.unify). +* [data.zip](https://github.com/clojure/data.zip) — zipper navigation, including + `clojure.data.zip.xml`; XML parsing via [jolt-lang/xml](https://github.com/jolt-lang/xml) + (which now ships `clojure.xml/parse`). * [tick](https://github.com/juxt/tick) — date/time over Jolt's `java.time`; `#time/…` literals via `time-literals`. * [transit-jolt](https://github.com/jolt-lang/transit-jolt) — Transit (JSON) read/write diff --git a/stdlib/clojure/zip.clj b/stdlib/clojure/zip.clj index a375742..af3e502 100644 --- a/stdlib/clojure/zip.clj +++ b/stdlib/clojure/zip.clj @@ -28,6 +28,16 @@ [root] (zipper vector? seq (fn [node children] (with-meta (vec children) (meta node))) root)) +(defn xml-zip + "Returns a zipper for xml elements (as from clojure.xml/parse), given a root + element" + [root] + (zipper (complement string?) + (comp seq :content) + (fn [node children] + (assoc node :content (and children (apply vector children)))) + root)) + (defn node "Returns the node at loc" [loc] (nth loc 0)) (defn branch? "Returns true if the node at loc is a branch"