Created StAX reader and writer to read/write directly from JDOM Documents... #105

merged 13 commits into from Mar 3, 2013


None yet
2 participants

gburgett commented Jan 2, 2013


I've been working for fun on an embedded XML database using JDOM 2.x. I found that I needed to use JAXB to serialize a Pojo directly to an Element. Unfortunately there was no direct way to do this, so I created a SAX Reader and a SAX Writer to read and write directly to JDOM Document objects in memory. Using this I was able to marshal and unmarshal to JDOM documents very easily:

JAXBContext context = JAXBContext.newInstance(Baz.class);

Baz baz;
JDOMStreamReader instance = new JDOMStreamReader(doc);
      baz = (Baz)context.createUnmarshaller().unmarshal(instance);

I think this would be valuable to include in the JDOM API. This would provide more options to convert to and from JDOM documents.

Also, if you'd like to check out my embedded XML db, take a look at it here

@gburgett gburgett Created SAX reader and writer to read/write directly from JDOM Docume…

Signed-off-by: gburgett <>

rolfl commented Jan 2, 2013

Hi Gordon. I am looking through your code and I have some questions/comments. I will contact you directly though.

rolfl and others added some commits Jan 3, 2013

@rolfl rolfl Move classes to separate package to make them part of coverage report…
… and also to make them self-contained. They may move again later.
@rolfl rolfl Fix eclipse compile warnings 04a4886
@rolfl rolfl move tests to jaxb package and fix eclipse compile warnings too. ca90504
@rolfl rolfl Add tests for NamespaceContext with changes to the class to match spec.
Also change base storage from list to array.
@rolfl rolfl getPrefix should return null for not-in-scope namespace URIs f1c765a
@rolfl rolfl Build round-trip test case, and feed it in to StreamWriter using othe…
…r JDOM Classes as feed-back. This allows a direct test.

Get the StreamWriter to have some success on the round-trip, but not 100% yet
@rolfl rolfl Get Namespace support working. Fix bug in StAXStreamProcessor related…
… to setPrefix declaration in stream prior to calling writeStartElement(). Add new features to NamespaceStack.
@gburgett gburgett Added round-trip tests for
Signed-off-by: gburgett <>
@rolfl rolfl Add mechanism to get number of attributes on an Element c67fdb2
@rolfl rolfl Add revised version of the JDOMStreamReader together with some implem…
…entation details for JDOM integration, and a round-trip test
@rolfl rolfl Merge branch 'stream_reader' of into stream_…

@rolfl rolfl Sort out failing test-case. Improve code namespace handling.
Remove enumeration for tracking state... it's easier with a simple boolean and some condition checks.

rolfl merged commit 98bbbd5 into hunterhacker:master Mar 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment