Hello,

I have difficulties marshalling JAXB objects into a dom4j document. I 
searched for it and what I found was using the JAXBWriter:

        jaxbWriter.startDocument();
        jaxbWriter.write(rootJaxbObject);
        jaxbWriter.endDocument();

As the classes I generated with xjc are no JAXBElement instances, I 
can't use this. How can I convert an object of generated JAXB classes 
(JAXB 2.2) to a jaxbObject which can be parsed to the writer?

The next way would be to convert it first to a DOMDocument which then 
can be converted to a dom4j document. I don't want to do too much 
conversions as performance happens, but I tried it anyway:

        DOMDocument doc = new DOMDocument();
        marshaller.marshal(dp, doc);
        DOMReader reader = new DOMReader();
        Document doc = reader.read(ddoc);

The problem here is that the xml declaration gets dropped somewhere. Is 
there a way to force the xml declaration? I assume that's a JAXB 
problem, because the marshaller thinks that doc is a fragment and not a 
whole document and omits the XML declaration. Can I add the declaration 
afterwards again?

The reason I want to convert it to a dom4j document is that I want to 
use prettyPrint on output. The DOM writer and the JAXB marshalling to a 
file is not very customizable and is causing indentation errors:

                             <A>
<B>43</B>
                             </A>

Thanks and kind regards
Paul.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to