From: Matt Gushee Date: 2002-09-12T12:04:42+09:00 Subject: Re: using REXML for XML document creation On Thu, Sep 12, 2002 at 11:04:57AM +0900, Ian Macdonald wrote: > > > Well, it should be obvious that I used a bare minimum of variable names > > for the sake of a minimal example. Surely you can figure out how to use > > additional variable names, or a stack, or some other common device to > > achieve the effect you want. > > Actually, I've been having a lot of trouble doing seemingly easy > things in REXML. Perhaps that's because REXML is my first taste of a > programmatic interface to XML. Hmm, ok ... could be that it seems more obvious to me than it is. Since I've been doing XML full time for 2 1/2 years, that's entirely possible. If the REXML documentation isn't enough, one thing that might be helpful is to study the DOM API, which is documented in many books and online resources. REXML's tree API isn't DOM-compliant, and isn't intended to be (thank God!), but it's conceptually similar enough that I think understanding the DOM would be helpful. The reason I say "thank God!" is that the DOM is just a big pain in the butt: it's a memory hog, it doesn't handle namespaces properly, it didn't have 'load()' and 'save()' methods until this year ... think I'll quit before I really get revved up. REXML is a breath of fresh air in comparison. For example, to add a new element to an existing element, using the W3C DOM interface you do this: newElement = document.createElement("foobarbaz") currentElement.appendChild(newElement) whereas in REXML you just do: currentElement.add_element("foobarbaz") et cetera. IMHO, if they DOM weren't blessed by the W3C it would have long ago vanished in favor of more elegant and intuitive interfaces. -- Matt Gushee Englewood, Colorado, USA mgushee@havenrock.com http://www.havenrock.com/