First off, unless you have a very good reason not to, you know the differences, and you know what you are doing, always use the "read" functions from clojure.edn rather than from clojure.core.
When you say "bad data", is it malformed (as in not valid EDN) or is it not conforming to the expected schema? If the former, you can either rely on the error reporting of clojure.edn/read-string, or (if you only need to parse a very limited subset of EDN) write your own parser that reports errors in a more suitable way for your use-case. Should you decide to go that way, you may want to look into instaparse. I would advise against going that way, though, but it's hard to know with the level of details you have provided about what tou are actually trying to achieve. If you get valid EDN but not the expected content, there are plenty of "validation" libraries that may be used for the task; two that directly come to mind are prismatic schema and validateur (slightly different use-cases, but, again, you have not really explained what you are trying to accomplish). If it is well formed and follows the expected schema, I am not sure how you can detect that it is not right. Maybe more unit tests? On Saturday, 12 March 2016, john <[email protected]> wrote: > I am producing clojure data with XSLT. At first I embraced the result in > a vector of vectors so that a single (read-string) would read the whole > structure in one take. > Unfortunately when the XSLT sheet produces bad data I don't see easily > what is going wrong. > > So is there an alternative for read-string? > > This is the code I am using right now. Instead of XSLT outputting a vector > of vectors I output vectors separated by "@@@" > --------------------- Code ------------------------------- > ;; dependency [clojure-saxon "0.9.4"] > > (def xsl-sheet (xml/compile-xslt (java.io.File. "sheet.xsl"))) > > (defn convert->transactions[[meta-params xml]] > (.toString (xsl-sheet (xml/compile-xml xml) meta-params))) > > (defn read-in [the-str] > (try (map > #(try (read-string %1) > (catch Exception e > (println "read-in Error:" (.getMessage e) > " token: " %1 > " token-pos" %2 > ))) > (str/split the-str #"@@@") (range 1000000000)))) > > > --------------------- Code ------------------------------- > > > Is there a more elegant way to read-in and get nice errors ? > > Many Greetings > > John > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > <javascript:_e(%7B%7D,'cvml','clojure%[email protected]');> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <javascript:_e(%7B%7D,'cvml','clojure%[email protected]');>. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
