Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I marshal a JAXB object to XOM?

Tags:

java

xml

jaxb

xom

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?

like image 744
skaffman Avatar asked Dec 31 '25 16:12

skaffman


2 Answers

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.

like image 160
laz Avatar answered Jan 03 '26 06:01

laz


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?

like image 21
Andrej Fink Avatar answered Jan 03 '26 05:01

Andrej Fink



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!