From: Bob Hutchison Date: 2006-08-01T21:20:42+09:00 Subject: Re: humanized Xml tree navigation Hi, On Jul 31, 2006, at 11:16 AM, Tim Bray wrote: > On Jul 31, 2006, at 6:16 AM, chiaro scuro wrote: > >> 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 > > Consider > > > foo > f�� > > > That's legal XML. Ruby n00b question: can you work around problems > like "vocab-item" and "first.form" in Ruby? -Tim I feel *compelled* to mention xampl (). Using the current version for ruby, the program looks like this: thing = open("xml/funnystuff.xml"){ | f | XamplObject.from_xml_string f.read } puts thing.pp_xml puts thing.class.name thing.first_form.first.content = 'hello there' puts thing.pp_xml The output like this: foo f�� XamplAdHoc::VocabItem hello there f�� The file xml/funnystuff.xml has Tim's example xml in it. The XamplAdHoc stuff is there because there is no namespace declarations in the xml and I didn't supply a default mapping to a Ruby Module. Xampl does a lot more than this (in particular it does a weak- transactional 'transparent' persistence kind of thing). It has been around in Java since the late 1990s (where it does 'real' transactions', CommonLisp for a couple of years, and Ruby for 18 months. I've written several programs well over 500 kloc using the Java version. Currently using xampl in place of ActiveRecord in a Rails project I'm working on (but you need the version I'm preparing to release for use with Rails, so please be patient). Cheers, Bob > ---- Bob Hutchison -- blogs at Recursive Design Inc. -- Raconteur -- xampl for Ruby --