Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GraphML target update
(def mytestxml
<graph edgedefault='directed'>
<node id='n1' />
<node id='n2' />
<node id='n3' />
<node id='n4' />
<edge id='e1' source='n1' target='n3' />
<edge id='e2' source='n2' target='n3' />
(def mytest (clojure.xml/parse ( (.getBytes mytestxml))))
(require '[ :as zip]
'[ :as zf])
(defn edit-target
"Edit target attribute of a GraphML edge"
(fn [node] (edit-target node new-target)))
([node new-target]
(assoc node
(assoc (:attrs node) :target new-target))))
;;; Code below doesn't work: returns a list of xml struct-maps
;;; where one n3 target is changed to n4 target
;;; Also returns empty list if no n3 target found
(defn update-edges
"Update edge targets from old-target to new-target"
[root old-target new-target]
(zf/xml-> (zip/xml-zip root)
(zf/attr= :target old-target)
#(zip/edit % edit-target new-target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.