Thanks, I think I have the idea. (ns ziptest (:require [clojure.zip :as zip] [clojure.xml :as xml] [clojure.contrib.zip-filter :as zf]) (:use clojure.contrib.zip-filter.xml) (:import (java.io ByteArrayInputStream)))
(def *xml-string* "<a1><b1><c1>a1b1c1</c1><c2>a1b1c2</c2></b1><b2><c1>a1b2c1</c1></b2></a1>") (defn string-to-zip [s] (zip/xml-zip (xml/parse (ByteArrayInputStream. (.getBytes s))))) (defn parse-xml [string] (doseq [x (xml-> (string-to-zip string) zf/descendants :c1)] (println "---> " (:content (first x))))) (parse-xml *xml-string*) [dr...@drowe][h:10013][J:0]> ./clojure src/ziptest.clj ---> [a1b1c1] ---> [a1b2c1] On Wed, Dec 2, 2009 at 11:38 AM, pmf <phil.fr...@gmx.de> wrote: > On Dec 2, 4:51 pm, Dennis <shr3ks...@gmail.com> wrote: > > The XML is of the form: > > ganglia > > multiple clusters > > multiple hosts > > multiple metrics > > Use XPath. Seriously, I hate XML and XSLT, but XPath is simply the > most concise way to extract things from a nested structure. Most XPath- > libraries allow for precompilation of XPath-expressions (similar to > RegEx-precompilation) and don't require the whole XML-file to reside > in memory, which makes this a nice solution for huge XML-files (though > in your case this is probably no issue). > > To get a list of all metrics in all hosts in all clusters, you'd > simply use the XPath-expression "ganglia/cluster/host/metric" against > an XML-document; recursive fetching (if clusters could contain other > clusters) could be done by using a double slash instead of a single > slash. > > A Clojure-solution for a similar expression language would be > clojure.contrib.zip-filter.xml, though I did not use it, but you might > try it out. > > -- > 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<clojure%2bunsubscr...@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