Constantine Gladky Constantine Gladky - 15 days ago 6
Java Question

How to marshall JAXBElement<Object> into org.w3c.dom.Element in Java using JAXB

I need to get Element object with request. I have ObjectFactory. I created an JAXBElement, and I need to marshall it to Element. Could anyone help me?

Answer

You could marshal to a DOMResult:

DOMResult res = new DOMResult();
marshaller.marshal(myJaxbElement, res);
Element elt = ((Document)res.getNode()).getDocumentElement();