Here is my attempt using enlive: (require '[net.cgrand.enlive-html :as html]) (import '[java.net URL]))
(def *url* "http://api.twitter.com/1/statuses/friends/barackobama.xml") (defn print-friends [url] (let [data (html/xml-resource (URL. url))] (doseq [user (html/select data [:user])] (let [name (html/text (first (html/select user [:screen_name]))) id (html/text (first (html/select user [:id])))] (println (str "username: " name " (" id ")")))))) (print-friends *url*) username: TruthSeekerZ1 (18346856) username: davidaxelrod (244655353) username: yankee13man (27474384) username: carbo (14171957) username: cadonato (27583520) username: pfeiffer44 (131144091) ... Hope that helps, Allen On Thu, Feb 3, 2011 at 5:25 PM, yiguang hu <yiguang...@gmail.com> wrote: > Hello, Can some one show me how to navigate through xml? > > I am trying to have some fun with clojure and think of doing a simple > xml navigation, it seems I didn't get the basics and not know how to > do this simple thing in clojure. > > For example, I try to get the user id and name of all barackobama > twitter friends. The following is as far as I can go and not know the > best way to retrieve the id and name of each user. > > (let [users (clojure.xml/parse > "http://api.twitter.com/1/statuses/friends/barackobama.xml")] > (:content users) > ) > > The following groovy scripts shows what I am trying to do: > > def data=new > XmlSlurper().parse("http://api.twitter.com/1/statuses/friends/barackobama.xml") > data.user.each{u-> > println u.screen_name.text()+" "+u.id.text() > } > > It would do me a big favor to understand clojure if some one could > show me how to do the above thing in clojure. > > Thanks > Yiguang > > -- > 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