Re: How can I parse this with clojure.contrib.zip-filter.xml ?
On Jan 23, 2:29 am, David Cabana wrote: > What I'd like to get from 'tickets' is something like ( ["Alice" > ["foo"]] ["Bob" ["bar" "baz"]]), that is, output that ties incidents > to customers. So far it has eluded me. "xml->" just returns a sequence of matches. If you want nested matches, you'll need to put another loop in. Perhaps something like: (defn tickets [xml] (for [ticket (zf/xml-> xml :ticket)] [(zf/xml1-> ticket :customer zf/text) (zf/xml-> ticket :item zf/text)])) That should work, but I haven't had the opportunity to test it, so forgive me if I'm wrong! :) - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How can I parse this with clojure.contrib.zip-filter.xml ?
James, That worked beautifully. I knew it had to be simple, but I was drawing a total blank. Thank you, David. On Fri, Jan 22, 2010 at 9:53 PM, James Reeves wrote: > On Jan 23, 2:29 am, David Cabana wrote: >> What I'd like to get from 'tickets' is something like ( ["Alice" >> ["foo"]] ["Bob" ["bar" "baz"]]), that is, output that ties incidents >> to customers. So far it has eluded me. > > "xml->" just returns a sequence of matches. If you want nested > matches, you'll need to put another loop in. Perhaps something like: > > (defn tickets [xml] > (for [ticket (zf/xml-> xml :ticket)] > [(zf/xml1-> ticket :customer zf/text) > (zf/xml-> ticket :item zf/text)])) > > That should work, but I haven't had the opportunity to test it, so > forgive me if I'm wrong! :) > > - James > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How can I parse this with clojure.contrib.zip-filter.xml ?
On 23 Jan 2010, at 02:53, James Reeves wrote: > On Jan 23, 2:29 am, David Cabana wrote: >> What I'd like to get from 'tickets' is something like ( ["Alice" >> ["foo"]] ["Bob" ["bar" "baz"]]), that is, output that ties incidents >> to customers. So far it has eluded me. > > "xml->" just returns a sequence of matches. If you want nested > matches, you'll need to put another loop in. Perhaps something like: > > (defn tickets [xml] > (for [ticket (zf/xml-> xml :ticket)] >[(zf/xml1-> ticket :customer zf/text) > (zf/xml-> ticket :item zf/text)])) The following is equally untested, but you can also just have xml-> call a function for each matching sub-element: (defn ticket [xml] [(zf/xml1-> xml :customer zf/text) (zf/xml-> xml :item zf/text)]) (defn tickets [xml] (zf/xml-> xml :ticket ticket))) -Steve -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en