[jdom-interest] Streaming JDOM

Paul Libbrecht paul at activemath.org
Mon Jul 24 00:46:09 PDT 2006


I have long been caressing the idea of a stream of JDOM elements... 
here's how I would see this:
One configures the streamer to fully jdom-load all elements matching a 
given name or ancestry-path, or with a configurable stream-filter which 
SAX-listens.
One lets the streamer call one's stream-listener, or the converse, with 
a jdom object of the indicated node, all loaded. Using to the children 
of the node is JDOM... which we all know.
Navigating to the ancestors of the node should always be possible, as 
JDOM again, but they would not have other descendants.

I believe this would bring the comfortable JDOM manipulations along with 
the performances of streaming-API.
I think I know at least one usage right now of this.

paul


Gregor Zeitlinger wrote:
> Hi,
>
> since I like JDOM, I use it whenever I can.
> For large documents, however, I have to use SAX, which seems
> uncessarily hard to use.
> I have seen that StAX is a better SAX, because it is pull rather than
> push based.
> It is still somewhat awkward, because you have Event objects and you
> have to keep track of endElement events.
>
> It occured to me, that this doesn't need to be the case. It is
> possible to have a Streaming XML API (i.e. where not the whole tree is
> in memory), which is (almost) as easy to use as JDOM:
>
> //reading
> reader.Element rootElement = doc.getRootElement();
> for (reader.Element child : element.getChildren()) {
>  System.out.println("child: " + child.getName());
>  for (reader.Element grandChild : child.getChildren()) {
>    System.out.println("grand child: " + grandChild.getName());
>    //and so on
>  }
> }
>
> //writing
> writer.Element c1 = root.addChild("c1");
> c1.setAttribute("a1", "v1");
> c1.addText("text");
> c1.addChild("c1.1").setAttribute("a2", "v2");
> root.addChild("c2");
>
> You don't need to keep track of endElement events, because it is clear
> from the way you use the methods.
>
> Since I like the simplicity of this idea, I was wondering if you would
> like to add this "Streaming JDOM" in JDOM.
>
> I have implemented a prototype, which uses SAX to read the XML.
>
> What do you think?
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3245 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.jdom.org/pipermail/jdom-interest/attachments/20060724/cbdfe149/smime.bin


More information about the jdom-interest mailing list