3

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769

2 Answers2

1

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.

Community
  • 1
  • 1
laz
  • 28,320
  • 5
  • 53
  • 50
  • Yeah, going from JAXB->DOM->XOM is what I'm currently stuck with, but it leaves a bad taste in my mouth. – skaffman Sep 15 '09 at 21:26
  • I understand completely. Perhaps this is an opportunity to create a contribution to XOM by creating the missing converter? ;) – laz Sep 16 '09 at 02:49
1

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?

Andrej Fink
  • 350
  • 2
  • 5