From: bbense+comp.lang.ruby.Sep.12.02@... Date: 2002-09-13T03:20:39+09:00 Subject: Re: using REXML for XML document creation -----BEGIN PGP SIGNED MESSAGE----- In article <20020912020359.GB8028@caliban.org>, Ian Macdonald wrote: >On Thu 12 Sep 2002 at 10:23:12 +0900, David Naseby wrote: > >> Try : >> doc = REXML::Document.new >> elt = doc.add_element("ADDRESSBOOK") >> parent = elt.add_element("CONTACTS") >> aContact = parent.add_element("CONTACT") >> aContact.add_attribute("FileAs","Macdonald, Ian") >> aContact = parent.add_element("CONTACT") >> aContact.add_attribute("FileAs","Contact, Another") >> aContact = parent.add_element("CONTACT") >> aContact.add_attribute("FileAs","Contact, YetAnother") >> >> Keep the reference to the parent element, and keep adding to it. > >Thanks. I'm not finding this module intuitive, which is in no way >intended as a criticism of REXML. Things which are essentially very >easy aren't coded in a way that is obvious to me. > - - XML only LOOKS obvious. I've only dabbled in it, but gets pretty complex when you want to do real things. It doesn't make things easy, only standardized. - - However, perhaps a more complex example[1] might actually make this simpler. I think the variable names[2] above are confusing the issue. contactNames = [ "name, one", "name, two", "name, three"] doc = REXML::Document.new addrbook = doc.add_element("ADDRESSBOOK") contactList = addrbook.add_element("CONTACTS") contactNames.each do |name| contactList.add_element("CONTACT").add_attribute("FileAs", name) end - - Booker C. Bense [1]- WARNING: untested code.... [2]- Maybe it's just me, but that kind of use of "temp" variables is a "code smell" to me. It seems very un-ruby like, no offense intended. -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBPYDXzmTWTAjn5N/lAQGR9gP6ArQY9WFzN1r9ARknLnWRJPOHhQyiGR+a kCUe5Kq8dqlc4H0f9GNXpcNON6bXjymaVNNF0OxVKweFQ+JsaUj11PmVmmJ5WXg+ k7fH/wj/pN10m3X7fglOJF7podvzoOau6Qlwydiu0WssoQDzBaKsU5cZH8Y37Xt8 VP/P6o5RP3c= =9D0D -----END PGP SIGNATURE-----