[jdom-interest] Converting elements from a SAX stream to JDOM elements

Tatu Saloranta cowtowncoder at yahoo.com
Mon Jul 20 12:58:16 PDT 2009

--- On Sat, 7/18/09, Colin Horne <colin at cdfh.org.uk> wrote:

> From: Colin Horne <colin at cdfh.org.uk>
> Subject: [jdom-interest] Converting elements from a SAX stream to JDOM ...
> I have a long (infinite) XML stream, which I intend to parse with SAX.
> Each individual element in the stream is small, and should
> be parsed with JDOM:
> <stream>
> <element>...</element>
> <element>...</element>
> </stream>
> So each <element> (and their children) are parsed with JDOM, but the
> <stream> as a whole is parsed with SAX. It would be

Do you absolutely have to use SAX for parsing here?
This is a rather typical case where STAX API works well for parsing.
Since you control traversal over input, it is easy to pass Stax XMLStreamReader for whoever builds JDOM trees, sub-tree by sub-tree.

For what it's worth, I wrote such a build a while ago:


and submitted it for JDOM. Not sure if it's included anywhere (under contribs, maybe).

Hope this helps,

-+ Tatu +-

ps. There are also plans to include this functionality in StaxMate [http://staxmate.codehaus.org] (issue [http://jira.codehaus.org/browse/STAXMATE-9])-- 2.0 has equivalent for DOM trees, but no JDOM support yet.


More information about the jdom-interest mailing list