On Wed, Dec 10, 2008 at 2:13 PM, Daniel Eklund <[EMAIL PROTECTED]> wrote: > > > As an off-hand comment made without careful reading, I can imagine > there being great utility in a special reader-syntax for paths. XSLT > embeds xpath, and groovy embeds gpath. I am unsure at this point the > exact capabilities of the zipper, so I don't know whether it's meant > to go to a single location in a tree (it seems this way)
That's right. Every navigation operation on a zip tree gives you a single tree with a new "current location". > or whether it > refers to a sequence of all tree nodes that satisfy the predicates of > the path (as xpath and gpath do). For the latter scenario, though, a > reader syntax for a "path" could be very useful. For this, you may be interested in clojure.contrib.zip-filter. It takes a single zip tree and then applies a series of filters, each of which may increase or reduce the number of nodes that match (so far), and/or map each node to some new object. It has a specialization for XML zip-trees that allows expressions like: (xml-> atom1 :entry :author :name text) ...where atom1 is an xml-zip tree of an atom feed. The above expression would return a seq of author name strings. It doesn't require reader macros or even regular macros. The 'xml->' function just takes a number of functions that it applies in order. The keywords are a special case for XML and act as if you wrote: (xml-> atom1 (tag= :entry) (tag= :author) (tag= :name) text) A primary benefit of not having a special syntax is that it's easy to drop in custom filtering and mapping functions. For example, get the titles of atom entries with odd-numbered ids: (xml-> atom1 :entry [:id text #(odd? (Integer. %))] :title text) --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---