Back

xml-zip (clj)

(source)

function

(xml-zip root)
Returns a zipper for xml elements (as from xml/parse), given a root element

Examples

clojure

(ns clojure.test-clojure.clojure-zip
  (:use clojure.test)
  (:require [clojure.zip :as zip]))


; zipper
;
; seq-zip
; vector-zip
; xml-zip
;
; node
; branch?
; children
; make-node
; path
; lefts
; rights
; down
; up
; root
; right
; rightmost
; left
; leftmost
;
; insert-left
; insert-right
; replace
; edit
; insert-child
; append-child
; next
; prev
; end?
; remove
clojure/clojure

(ns clojure.test-clojure.clojure-zip
  (:use clojure.test)
  (:require [clojure.zip :as zip]))


; zipper
;
; seq-zip
; vector-zip
; xml-zip
;
; node
; branch?
; children
; make-node
; path
; lefts
; rights
; down
; up
; root
; right
; rightmost
; left
; leftmost
;
; insert-left
; insert-right
; replace
; edit
; insert-child
; append-child
; next
; prev
; end?
; remove
babashka/babashka
(ns babashka.impl.clojure.zip
  {:no-doc true}
  (:require [clojure.zip :as zip]
            [sci.core :as sci :refer [copy-var]]))

(def zip-namespace
  {'zipper       (copy-var zip/zipper zip-ns)
   'seq-zip      (copy-var zip/seq-zip zip-ns)
   'vector-zip   (copy-var zip/vector-zip zip-ns)
   'xml-zip      (copy-var zip/xml-zip zip-ns)
   'node         (copy-var zip/node zip-ns)
   'branch?      (copy-var zip/branch? zip-ns)
   'children     (copy-var zip/children zip-ns)
   'make-node    (copy-var zip/make-node zip-ns)
   'path         (copy-var zip/path zip-ns)
   'lefts        (copy-var zip/lefts zip-ns)
   'rights       (copy-var zip/rights zip-ns)
   'down         (copy-var zip/down zip-ns)
   'up           (copy-var zip/up zip-ns)
   'root         (copy-var zip/root zip-ns)
   'right        (copy-var zip/right zip-ns)
   'rightmost    (copy-var zip/rightmost zip-ns)
   'left         (copy-var zip/left zip-ns)
   'leftmost     (copy-var zip/leftmost zip-ns)
   'insert-left  (copy-var zip/insert-left zip-ns)
   'insert-right (copy-var zip/insert-right zip-ns)
   'replace      (copy-var zip/replace zip-ns)
   'edit         (copy-var zip/edit zip-ns)
   'insert-child (copy-var zip/insert-child zip-ns)
   'append-child (copy-var zip/append-child zip-ns)
   'next         (copy-var zip/next zip-ns)
   'prev         (copy-var zip/prev zip-ns)
   'end?         (copy-var zip/end? zip-ns)
   'remove       (copy-var zip/remove zip-ns)})
babashka/babashka
(require '[clojure.data.xml :as xml]
         '[clojure.data.zip.xml :as xmlz]
         '[clojure.zip :as zip])

(-> xml
    xml/parse-str
    zip/xml-zip
    (xmlz/xml1-> :pom :version zip/down zip/node))
;; => 1.0.0
babashka/babashka
(ns clojure.data.zip-test
  (:require [clojure.test :as t :refer [deftest is]]
            [clojure.data.xml :as xml]
            [clojure.zip :as zip]
            [clojure.data.zip.xml :refer [attr attr= xml1->]]))

(deftest xml1-test
  (let [xml   (zip/xml-zip (xml/parse (java.io.StringReader. data)))]
    (is (= "person"
         (xml1-> xml :character [(attr= :name "alice")] (attr :type))))
    (is (= "march hare"
         (xml1-> xml :character [(attr= :type "animal")] (attr :name))))))
boot-clj/boot
(ns boot.pom-test
  (:require [boot.pom :as pom]
            [clojure.test :as test :refer [deftest is testing]]
            [clojure.zip :as zip]
            [clojure.data.xml :as dxml]
            [clojure.data.zip.xml :as dzxml]))

  (testing "pom-xml :parent"
    (let [parent-loc (-> {:project 'group/my-plugin
                          :version "1.2.0"
                          :parent '[org.codehaus.mojo/my-parent "2.0"]}
                         pom/pom-xml
                         pr-str
                         dxml/parse-str
                         zip/xml-zip
                         (dzxml/xml1-> :parent))]
      (is (not (nil? (dzxml/xml1-> parent-loc :groupId "org.codehaus.mojo"))) "I should contain a :groupId tag with correct content")
      (is (not (nil? (dzxml/xml1-> parent-loc :artifactId "my-parent"))) "It should contain a :artifactId tag with correct content")
      (is (not (nil? (dzxml/xml1-> parent-loc :version "2.0"))) "It should contain a :version tag with correct content"))))