7

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?

2 Answers 2

16

You could marshal to a DOMResult:

DOMResult res = new DOMResult();
marshaller.marshal(myJaxbElement, res);
Element elt = ((Document)res.getNode()).getDocumentElement();
Sign up to request clarification or add additional context in comments.

Comments

5

In addition to Ian's answer, I suppose to first create a Document, as the unchecked cast can be omitted this way:

Document document =
    DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXB.marshal(jaxbElement, new DOMResult(document));
Element element = document.getDocumentElement();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.