[jdom-interest] JDOM Documents from JAXBContext
Anderson, Paul D
paul.d.anderson at boeing.com
Thu Oct 26 10:07:46 PDT 2006
I asked this question a few months ago and received a stunning silence
in return. Is there anyone who can help?
-----Original Message-----
From: Anderson, Paul D
Sent: Friday, July 15, 2005 1:21 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] JDOM Documents from JAXBContext
The project I'm involved in uses JAXB 2.0 for marshalling/unmarshalling
of XML objects, but internally I'd like to use JDOM for manipulating the
XML.
I'm having trouble finding an efficient way to convert the JAXBContext
output to JDOM. The most straightforward solution I can come up with is
this:
// The object to be marshalled.
Test obj = new Test();
// this is boilerplate to create a Marshaller
JAXBContext jc = JAXBContext.newInstance( Test.class );
Marshaller m = jc.createMarshaller();
// once I have the Marshaller I can marshal to Files, Writers,
OutputStreams, etc.
// The most straightforward path to JDOM I can find is to
marshal to a org.w3c.dom.Document...
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.marshal( obj, doc );
// ... and then convert the org.w3c.dom.Document to a
org.jdom.Document
Org.jdom.DOMBuilder jdb = new org.jdom.DOMBuilder();
org.jdom.Document jdoc = jdb.build(doc);
This works okay, but it seems inefficient to create the
org.w3c.dom.Document.
The marshaller will also marshal to a SAX ContentHandler or a
javax.transform.sax.SAXResult but I can't find a way to hook these into
the JDOM SAXBuilder.
Does anyone know of a better way to do this?
Paul D. Anderson
Software Engineer
Boeing Phantom Works
206-655-4716
paul.d.anderson at boeing.com
"Notions and scruples [are] like spilt needles, making one afraid of
treading, or sitting down, or even eating." George Eliot, Middlemarch
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list