How do I marshal a JAXB object to XOM?

I am trying to figure out what bits I need to hook up so that the JAXB POJO marshal in a XOM document and vice versa.

The JAXB interface marshal methods Marshaller

accept various targets such as Result

, but none of them has an XOM adapter. Annoyingly, the XOM API has an implementation XOMResult

, but it is protected and only used internally.

Is there any other way that I can marshal to / from the XOM without resorting to String or byte buffers?

+2


source to share


2 answers


I'm not sure if you are negative about using the DOM for this, as you are probably using XOM to avoid the DOM! Anyway, with the JAXB Binder, as described here along with the XOM DOMConverter , you can go from JAXB to DOM to XOM without using a string or byte buffer.

It's too bad that XOM doesn't have a utility to create a XOM document from a SAX ContentHandler, since JAXB also supports sorting an instance of that object. XOM has a SAXConverter that can create a ContentHandler from a document, but not vice versa.



Here is a thread that pertains to this on the XOM mailing list of interest .

0


source


I found an old nux project :

a http://acs.lbl.gov/software/nux//api/nux/xom/pool/XOMUtil.html

jaxbMarshal / jaxbUnmarshal use DOMConverter; - (



b. http://acs.lbl.gov/software/nux/api/nux/xom/io/StaxUtil.html ... also includes an XOM Builder implementation that uses the STAX parser instead of the SAX parser; plus a representation of the XMLStreamReader implementation from the underlying document or XOM fragment; plus other tools.

StaxUtil.createXMLStreamReader (Node root) Creates and returns a StAX XMLStreamReader parser implementation that reads from the underlying XOM Node; usually a document or fragment (subtree); Ideal for efficiently converting XOM tree to SOAP / AXIOM, JAXB 2, JiBX, or XMLBeans, for example when converting XQuery results incrementally via Unmarshaller, possibly in conjunction with StreamingPathFilter.

Maybe this can help?

+1


source







All Articles