This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-06
Channels
- # announcements (4)
- # aws (2)
- # beginners (48)
- # calva (39)
- # cljsrn (12)
- # clojure (98)
- # clojure-dusseldorf (1)
- # clojure-serbia (2)
- # clojure-spec (13)
- # clojure-uk (13)
- # clojurescript (97)
- # code-reviews (1)
- # datomic (14)
- # fulcro (24)
- # jobs-discuss (160)
- # juxt (1)
- # luminus (2)
- # nrepl (1)
- # off-topic (1)
- # other-languages (1)
- # overtone (1)
- # perun (6)
- # protorepl (16)
- # re-frame (20)
- # reagent (1)
- # reitit (6)
- # rum (8)
- # shadow-cljs (96)
- # spacemacs (8)
- # specter (4)
- # tools-deps (18)
- # uncomplicate (1)
- # vim (1)
i have some xml:
'({:tag :CategoryName_1, :attrs {}, :content ("cats")}
{:tag :CategoryId_1, :attrs {}, :content ("cat260062")}
{:tag :Items,
:attrs {},
:content
({:tag :ItemId, :attrs {}, :content ("1000388464506500")}
{:tag :ItemId, :attrs {}, :content ("1000388464506405")})})
that i'd like to turn into into this map:
{:CategoryName_1 "cats", :CategoryId_1 "cat260062", :Items ["1000388464506500" "1000388464506405"]}
that is, for recursive :content
s, i'd like them collected into a vector, and for non-recursive, their tags and contents are key value pairsthe following works, but i'm using glue code to compensate for my lack of specter experience:
(let [top-level-tags [:CategoryName_1 :CategoryId_1]
xml '({:tag :CategoryName_1, :attrs {}, :content ("cats")}
{:tag :CategoryId_1, :attrs {}, :content ("cat260062")}
{:tag :Items,
:attrs {},
:content
({:tag :ItemId, :attrs {}, :content ("1000388464506500")}
{:tag :ItemId, :attrs {}, :content ("1000388464506405")})})
map-by-tags (group-by :tag xml)
top-level (sp/transform
[sp/MAP-VALS]
(fn [v] (-> v first :content first))
(select-keys map-by-tags top-level-tags))
Items (sp/select
[:Items sp/ALL :content sp/ALL :content sp/FIRST]
map-by-tags)]
(merge top-level {:Items Items}))