Fork me on GitHub
#specter
<
2023-02-11
>
nyor.tr01:02:21

I'm trying to transform an XML tree, like the following:

(def xml {:tag :main,
 :attrs {},
 :content
 ["\n    "
  {:tag :parent,
   :attrs {},
   :content
   ["\n        "
    {:tag :child1, :attrs {}, :content ["value1"]}
    "\n        "
    {:tag :child2, :attrs {}, :content ["value2"]}
    "\n        "
    {:tag :child3, :attrs {}, :content ["value3"]}
    "\n    "]}
  "\n    "
  {:tag :parent,
   :attrs {},
   :content
   ["\n        "
    {:tag :child1, :attrs {}, :content ["value4"]}
    "\n        "
    {:tag :child2, :attrs {}, :content ["value5"]}
    "\n        "
    {:tag :child3, :attrs {}, :content ["value6"]}
    "\n        "
    {:tag :child4, :attrs {}, :content []}
    "\n    "]}
  "\n    "
  {:tag :parent, :attrs {}, :content []}
  "\n"]})
into a flat data structure like:
(def flat-xml [{[:main :parent :child1] "value1"
                [:main :parent :child2] "value2"
                [:main :parent :child3] "value3"}
               {[:main :parent :child1] "value4"
                [:main :parent :child2] "value5"
                [:main :parent :child3] "value6"
                [:main :parent :child4] ""}])
could this be done using specter?

Nick17:03:22

I would also check out: https://github.com/turtlegrammar/faconne it's pretty awesome at doing you are looking to do

nathanmarz19:02:35

@nyor.tr yes, you would use recursive-path and collect-one