From: Julian Fitzell Date: 2001-11-14T12:24:48+09:00 Subject: [ruby-talk:25146] Re: REXML Question (Re: XML libraries (Re: Re: ruby and webser vices)) Well, as you probably know I've been working off and on on a Jabber library as well. I've had similar problems with every parser I've tried but each one just needs a workaround. My solution has been to write an XML stream class that handles a lot of this stuff. I've yet to rewrite it to use REXML though I think I will try. Once a standard API is decided on, I will definitely write a good XML stream class that fits in with the API and post it to be included. The tricky thing with XML streams is also that when you are receiving data, you need to essentially ignore the opening tag (though not actually ignore it, you need the attributes) and then generate an event every time a 2nd level packet comes in and return all that XML as a complete document. It always feels a little hackish but it's better than tracking the incoming tags yourself - at least it's handled by the XML stream class. Julian On 14/11/2001 at 5:10 AM Sean Russell wrote: >Ben Schumacher wrote: > >> However, when I create the element with REXML it ends up being closed: > >How have you seen this done in other XML toolkits? > >REXML closes tags, because any call to Element.write (should) produce a >valid XML document. This requires that all tags be closed. > >Specifically, REXML will *read* documents in a stream, but it won't create >them that way; internally, all REXML documents that are programmatically >created are document trees. > >> > xmlns:stream='http://etherx.jabber.org/streams'/> >> >> I figure I could probably work around this easily enough by writing the >> output to a string and then removing the slash, but I was wondering if >> somebody else had a better solution? (I could, of course, build the >entire >> opening element manually and not use REXML, but I'd prefer not to do >> this.) > >Hmmm. Interesting problem. If the stream is one large document on a >single socket, it might be easier to hand-craft the opening tag (it isn't >complicated, is it?) and then use the XML toolkit to generate the >individual tags, closing the tag at the end by hand. > >I could provide a solution in REXML by providing a Element.start_tag() and >Element.end_tag() methods, but I'm hesitant to complicate the API if this >is a single-use (or extremely rare) need. > >I'm open to suggestions. > >-- >--- SER