Sean, I probably did not make it clear, but I am using parse. The second line of handle-xml function in my original E-Mail has the parse in it. I then iterate over the xml-seq.
I am also using: (ns zod (:require [clojure.contrib.http.agent :as http]) (:import (java.util Timer TimerTask)) (:use [clojure.xml :only (parse)])) -- Dennis On Wed, Dec 2, 2009 at 10:23 AM, Sean Devlin <francoisdev...@gmail.com>wrote: > Try the clojure.xml namespace. There's a funciton parse in there that > should help. > > On Dec 2, 10:51 am, Dennis <shr3ks...@gmail.com> wrote: > > Howdy, > > > > Being new to clojure, I am having a difficult time parsing XML in an > elegant > > manner. I am pulling metric information from a ganglia server as XML and > > then parsing it. The below function works but it makes me feel icky. I > was > > hoping for some tips. > > > > The "dc" variable contains a map with some data center information (not > > really interesting), and the "stream" variable comes from http.agent. > > > > (defn handle-xml [dc stream] > > (let [xml-out (xml-seq (parse (http/stream stream)))] > > (doseq [x xml-out] > > (doseq [y (:content x)] > > (doseq [z (:content y)] > > (doseq [a (:content z)] > > (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs > > a)) (:TN (:attrs a))))))))) > > > > The XML is of the form: > > ganglia > > multiple clusters > > multiple hosts > > multiple metrics > > > > Example of the XML: > > <GANGLIA_XML VERSION="3.0.7" SOURCE="gmond"> > > <CLUSTER NAME="cluster.example.com" LOCALTIME="1258396022" > > OWNER="unspecified" LATLONG="unspecified" URL="unspecified"> > > <HOST NAME="server.example.com" IP="127.0.0.1" REPORTED="1258396019" > TN="3" > > TMAX="20" DMAX="86400" LOCATION="unspe > > cified" GMOND_STARTED="1255757736"> > > <METRIC NAME="disk_total" VAL="1320.124" TYPE="double" UNITS="GB" > TN="6684" > > TMAX="1200" DMAX="0" SLOPE="both" SOURCE="gmond"/> > > <METRIC NAME="cpu_speed" VAL="2493" TYPE="uint32" UNITS="MHz" TN="682" > > TMAX="1200" DMAX="0" SLOPE="zero" SOURCE="gmond"/> > > ... > > > > Thanks, > > Dennis > > -- > 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