From: David Naseby Date: 2002-09-12T10:23:12+09:00 Subject: RE: using REXML for XML document creation > -----Original Message----- > From: Ian Macdonald [mailto:ian@caliban.org] > On Thu 12 Sep 2002 at 01:45:01 +0900, Matt Gushee wrote: > > > > > > > > > > > > > > > > > > > > require 'rexml/document' > > > > doc = REXML::Document.new > > elt = doc.add_element("ADDRESSBOOK") > > elt = elt.add_element("CONTACTS") > > elt = elt.add_element("CONTACT") > > elt.add_attribute("FileAs","Macdonald, Ian") > > Actually, how do I add the next element? If I just use > add_element again, I get the next nested inside the first > one. > 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. David.