From: Aleksi Date: 2005-04-11T21:54:38+09:00 Subject: Re: groovy-like xml selection Robert Klemme wrote: > "Luke Graham" schrieb im Newsbeitrag > >>Hi list, >> >>Ive taken a quick look at groovy for the first time, and saw an >> >> >> >> >> >> >> >> >> >>foo.bar.star.select { |it| it[@age] == "1" && it.parent.name == "bar" >>&& it.star.count == 0 } >> > > > REXML comes pretty close. I'm sure with a small addition like this one > you get pretty far: > > class REXML::Element > def method_missing(sym,*a,&b) > elements[sym.to_s] or super > end > end > > Maybe you should add this to module REXML::Node. I said a week ago about this simple REXML wrapup: http://groups-beta.google.com/group/comp.lang.ruby/browse_frm/thread/f4e64a6983199c70/c3b1b15741232e9a?q=comp.lang.ruby+simplexml&rnum=1#c3b1b15741232e9a I'm not sure this is what you meant, but thought to point to it anyway. Effectively you can write code like given in example at http://www.cs.helsinki.fi/u/kaniemel/SimpleXML/doc/ xml = SimpleXML.load(xml_string) # or File puts xml.movie[0].plot # => "\n Whether you..." >>Im sure someones done the xml->object (method in this case) thing, but >>has the native path trick been tried in ruby yet? I'm not sure what you mean with native path trick. But if that's being able to write xml.foo which finds a correct branch in DOM tree and allows one to continue with that branch, yes this module already implements it over REXML. I have currently no plans to go forward with it, but I've been pondering if there should be generic API for accessing and modifying and underlying implementations over whatevery DOM traversal API is present be it REXML or any of the 15 libraries out there :). - Aleksi