From: Ian Macdonald Date: 2002-09-12T10:19:14+09:00 Subject: Re: using REXML for XML document creation On Thu 12 Sep 2002 at 01:45:01 +0900, Matt Gushee wrote: > On Thu, Sep 12, 2002 at 12:59:42AM +0900, Ian Macdonald wrote: > > > > As an REXML beginner, I'm having trouble figuring out how to nest one > > element within another. Basically, I need something like this: > > > > > > > > > > > > > > > > Right now, I can create each element sequentially, but I'm having a > > hard time getting all the elements inside the > > element. > > You're probably expecting it to be harder than it is. If you've ever > worked with the DOM, building a document with REXML is similar but > simpler. For example: > > 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. Ian -- Ian Macdonald | Chastity: The most unnatural of the sexual ian@caliban.org | perversions. -- Aldous Huxley | | |