Question

I'm trying to figure out what bits I need to plug together to marshal a JAXB POJO to a XOM document, and vice versa.

The JAXB Marshaller interface's marshal methods take various targets, such as Result, but none of them have a XOM adapter. Irritatingly, the XOM API does have a XOMResult implementation, but it's package protected, and only used internally.

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

Was it helpful?

Solution

I'm not sure if you are adverse to using DOM to accomplish this, as you're probably using XOM to avoid DOM! Anyway, using a JAXB Binder as described here along with XOM's DOMConverter, you can go from JAXB to DOM to XOM without using a String or a byte buffer.

It is too bad that XOM doesn't have a utility to create a XOM Document from a SAX ContentHandler, since JAXB also supports marshalling to an instance of that object. XOM has a SAXConverter that can create a ContentHandler from a Document, but not the other way around.

Here's a thread that relates to this on the XOM-interest mailing list.

OTHER TIPS

I found old project nux:

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 a XOM Builder implementation that uses a StAX parser instead of a SAX parser; plus a XMLStreamReader implementation reading from an underlying XOM Document or fragment; plus other tools.

StaxUtil.createXMLStreamReader(Node root) Constructs and returns a StAX XMLStreamReader pull parser implementation that reads from an underlying XOM Node; typically a Document or fragment (subtree); Ideal for efficient conversion of a XOM tree to SOAP/AXIOM, JAXB 2, JiBX or XMLBeans, for example when incrementally converting XQuery results via an Unmarshaller, perhaps in combination with a StreamingPathFilter.

May be this can help?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top