This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-09
Channels
- # beginners (205)
- # boot (6)
- # cider (22)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (97)
- # clojure-dev (61)
- # clojure-greece (40)
- # clojure-italy (8)
- # clojure-russia (16)
- # clojure-spec (18)
- # clojure-uk (34)
- # clojurescript (14)
- # community-development (1)
- # cursive (45)
- # datomic (39)
- # fulcro (66)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (8)
- # parinfer (98)
- # portkey (8)
- # re-frame (81)
- # reagent (54)
- # remote-jobs (17)
- # ring (2)
- # shadow-cljs (217)
- # spacemacs (32)
- # sql (24)
- # test-check (6)
- # unrepl (73)
- # yada (12)
So I've enjoyed my foray into zippers this week. I wanted to make a small change to a single value in ~ 100 xml files and reading / parsing / zipping xml
(clojure.zip/xml-zip (clojure.data.xml/parse ( "path-to-data.xml")))
worked a treat.
Using zip/down, and zip/edit was also pretty easy to grok. Now I just needed to write back the file. Simple, just invoke clojure.data.xml/emit
on the zip? Yes, on simple xml. However my gpx contains xml and emit
fails with XMLStreamException Prefix cannot be null com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeAttribute (XMLStreamWriterImpl.java:575)
probably related to https://groups.google.com/forum/#!topic/clojure/Um3aC_z0--4
Am I being stupid? Should I fall back to clojure.xml? How would you approach this seemingly simple task? I ask as most googling of zippers + xml return pages circa 2014 so am I just doing this an old fashioned error-prone or non-idiomatic way?Not out of date at all, it's just that they solve a specific problem that few people have. After the hype was over, people had little left to say.
Oh no, I'm using the stable org.clojure/data.xml "0.0.8"
release. I'll try the alpha at lunchtime. Cheers.
That worked a treat, cheers. Now, I've just got to work out the round trip qname retrieval / setting as I want to do a similar string change in the xml, nothing more complex.
@U064B4L0K any recommendations on materials you found useful to understand zippers? Not looked into them at all
@U0DPX8ZQB I mainly used http://blog.korny.info/2014/03/08/xml-for-fun-and-profit.html
So, without attempting to apply namespaces, emit-str understandable generates a
ExceptionInfo Auto-generating prefixes is not supported for content-qnames. Please declare all URIs used in content qnames. clojure.core/ex-info (core.clj:4617)
, and adding all the namespaces for gpx xmlns:gh="" xmlns:gs="" xmlns:os="" xmlns:xsi="" xmlns="" creator="OSMaps" version="1.1" xsi:schemaLocation="">
like (xml/emit-str (first (edit-title (second all-files))) {:xmlns/gh "" :xmlns/gs "" :xmlns/os "" :xmlns/xsi "" :xmlns ""})
generates a IllegalArgumentException No value supplied for key: {:xmlns/gh "", :xmlns/gs "", :xmlns/os "", :xmlns/xsi "", :xmlns ""} clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
exception 😕@U0DPX8ZQB The way I think about zippers is that they're about taking a data structure (e.g. {:foo {:bar 1}}
) and adding a location (`[:foo]`). You can get the (value)
at the current point (which would be {:bar 1}
), and you can "move", so do things like (down)
which would change your position to [:foo :bar]
and (value)
would be 1
, or you could go (up)
to []
and the value would be {:foo {:bar 1}}
@paulspendI don't know much about the namespacing system in clojure.data.xml, but that doesn't look like how we use it.
@U064B4L0K Oh, the API changed recently, so that's probably what you're running into.
Gotcha, I saw a sample on the readme with ‘{:xmlns/foo "http://www.w3.org/199’ but it was for xml, not emit-str opts!
Morning btw, how rude 😉
Not out of date at all, it's just that they solve a specific problem that few people have. After the hype was over, people had little left to say.
Morning
morning
So, without attempting to apply namespaces, emit-str understandable generates a
ExceptionInfo Auto-generating prefixes is not supported for content-qnames. Please declare all URIs used in content qnames. clojure.core/ex-info (core.clj:4617)
, and adding all the namespaces for gpx xmlns:gh="" xmlns:gs="" xmlns:os="" xmlns:xsi="" xmlns="" creator="OSMaps" version="1.1" xsi:schemaLocation="">
like (xml/emit-str (first (edit-title (second all-files))) {:xmlns/gh "" :xmlns/gs "" :xmlns/os "" :xmlns/xsi "" :xmlns ""})
generates a IllegalArgumentException No value supplied for key: {:xmlns/gh "", :xmlns/gs "", :xmlns/os "", :xmlns/xsi "", :xmlns ""} clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
exception 😕got told today that the company i work for is going to be moving away from doing development work in March (which is fair enough). i haven't really been enjoying my work for a while now, and had recently been thinking of getting around to updating my CV and finding some new work, so i'm not too disappointed (though i will miss my colleagues) - but now i have until March to 🙂