In article <62e8012c0607310632hb44a0b6md149d6462d20130c / mail.gmail.com>, Pedro Cộte-Real <pedro / pedrocr.net> wrote: >On 7/31/06, chiaro scuro <kiaroskuro / gmail.com> wrote: >> Does anybody know of a library that allows to go through an xml tree as if >> it were made of normal objects? >> >> I have seen e4x on rubyforge, but it doesn't seem to work. simplexml returns >> hashes rather than employing dynamic method calls >> >> What I need to do is to be able to traverse an xml document as in: >> >> * people.each_person {...} >> * people.person[2].name >> * people.person.name #takes the first person >> * people.person.size > >My xmlcodec project will do this but you'll need to write some simple >classes to do it. For this case, something like: > >class PeopleFormat < XMLElement > xmlformat 'People Format' >end > >class People < PeopleFormat > elname :people > xmlsubel_mult :person >end > >class Person < PeopleFormat > elname :person > xmlattr :name > xmlattr :size >end > >With this you can do: > >people = PeopleFormat.import_xml_text(myXMLTextOrFile) >people.person.each {|p| ...} >people.person.first.name >people.person[2].type > >You can find it at http://xmlcodec.rubyforge.org > Nice. I've done this sort of thing, but much more 'manually' than you show here. Phil