[jdom-interest] [off-topic] SaxPath?

Attila Szegedi szegedia at freemail.hu
Tue Oct 2 06:30:03 PDT 2001


Looks promising. I'd definitely be interested in seeing it. My idea takes this a step further; I still want to expose the objects through JDOM core classes' subclasses so template engines (like Velocity) can use it. It'd go something like:

...
// register interest in specific children by asking for a list
List fooChildren = element.getChildren("foo");
List barChildren = element.getChildren("bar");
// start iterating over children lists. Each element is removed from list once read
// (the iterator performs destructive readout). At the point first iterator.next() or 
// hasNext() is called it is no longer possible to register further lists
Iterator foos = fooChildren.iterator();
Iterator bars = barChildren.iterator();
while(foos.hasNext()) { do something };
while(bars.hasNext()) { do something };
...
As you can see, just plain JDOM API usage - nothing special on API level.

If "element" was itself retrieved from an iterator, then a hasNext() or next() on that iterator would invalidate fooChildren, barChildren, foos and bars (as the SAX stream would pass over them to the next peer of their parent).
Essentially, only methods that would be allowed on an Element would be getChildren(), getContent(), and getAttributes() (attributes would not have destructive readout semantics, of course). And the only method you could call on a list returned from getChildren() and getContent() would be iterator().

These methods would constrain traversing the object model in the same order as they appear in the XML stream - which is natural since the backend is SAX. The tricky part of this stuff is that it needs to be implemented as a two-threaded producer-consumer pattern (the SAX parser executes on a separate thread as a producer, while the object model acts as the consumer).

Attila.


----- Original Message ----- 
From: "Laurent Bihanic" <laurent.bihanic at atosorigin.com>
To: "Attila Szegedi" <szegedia at freemail.hu>
Cc: <jdom-interest at jdom.org>
Sent: 2001. október 2. 13:12
Subject: Re: [jdom-interest] [off-topic] SaxPath?


> 
> Attila Szegedi wrote:
> 
> > It's strange - just last night I was thinking about an XML object model that would be dinamically generated backed by a SAX parser, always containing only the current element and its ancestors, and eventually a single level of children. It came to my mind as I thought about transforming XML documents using template engines and stream-based XML (that is, SAX) instead of load-it-all-in-memory approach (JDOM). I'd be interested in similar stuff myself -- or write one if there isn't any. 
> > 
> 
> 
> Hi,
> 
> Maybe I've already implemented what you are looking for:
> http://lists.denveronline.net/lists/jdom-interest/2001-August/007861.html
> 
> If you are interested, I can send you the latest version.
> 
> Laurent
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2848 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20011002/76f3878b/smime.bin


More information about the jdom-interest mailing list