I have been fooling around with clojure.contrib.zip-filter.xml, and
feel like I'm stuck on something that should be simple.
Below is code showing what I'm talking about. I'm trying to parse some
simple xml, but can't quite get what I'm after.

(ns foo
  (:require [clojure.xml :as xml])
  (:require [clojure.zip :as zip])
  (:require [clojure.contrib.zip-filter.xml :as zf]))

;; read and parse xml string
(defn parse-str [s]
   (zip/xml-zip (xml/parse (new org.xml.sax.InputSource
                           (new java.io.StringReader s)))))

;; illustrative xml string
(def incidents (parse-str
  "<incidents>
     <ticket>
       <customer>Alice</customer>
       <item>foo</item>
     </ticket>
     <ticket>
       <customer>Bob</customer>
       <item>bar</item>
       <item>baz</item>
     </ticket>
  </incidents>"))


(defn customers [xml]
  (zf/xml-> xml :ticket :customer zf/text))

(defn items [xml]
  (zf/xml-> xml  :ticket :item zf/text))

(defn tickets [xml]  ;; not quite right
  (zf/xml-> xml :ticket  zf/text))

;;
;;(items incidents)          yields ("foo" "bar" "baz")
;;(customers incidents)  yields ("Alice" "Bob")
;;(tickets incidents)        yields ("Alicefoo" "Bobbarbaz")
;;

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.

If you can offer any suggestions, I'd sure appreciate it.

David

-- 
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

Reply via email to