From: Tomasz Wegrzanowski Date: 2006-08-06T19:52:28+09:00 Subject: Re: magic/xml library for easy XML processing On 8/6/06, Zed Shaw wrote: > On Sat, 2006-08-05 at 10:17 +0900, Tomasz Wegrzanowski wrote: > > doc = XML.from_url "http://t-a-w.blogspot.com/atom.xml" > > doc.children(:entry).children(:link) {|c| > > print "#{c[:title]}\n#{c[:href]}\n\n" if c[:rel] == "alternate" > > } > > > > I'd like to have it work like Hpricot as well: > > (doc/:entry/:link).each do {|c| > ... > } > > Especially considering you overload [] to get attributes, why not / to > get children? Basically because there are three reasonable things to with node[:foo]: * return attribute :foo * return the first child with tag :foo * return list of children with tag :foo Ruby is not Perl, so we cannot have both 2 and 3 folded into one, and doing only second or only third doesn't sound that convincing ;-) Another issue is that I'd have to overload Array#/ to get (doc/:entry/:link) working, and that would have much higher mental cost than adding long-named method like #children to it. Or use something else than an Array for sequences of XML nodes (hpricot does so with Hpricot::Elements), but that wouldn't be nice. I'll look at it again after I have all W3C XQuery Use Cases recoded :-) -- Tomasz Wegrzanowski [ http://t-a-w.blogspot.com/ ]