From: "Pedro CĂ´rte-Real" Date: 2006-07-31T22:32:36+09:00 Subject: Re: humanized Xml tree navigation On 7/31/06, chiaro scuro 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 Cheers, Pedro.