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?


You could marshal to a DOMResult:

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

2 に答える 2

15

次のようにマーシャリングできますDOMResult

DOMResult res = new DOMResult();
marshaller.marshal(myJaxbElement, res);
Element elt = ((Document)res.getNode()).getDocumentElement();
于 2012-11-26T17:07:15.327 に答える
4

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();
于 2016-11-21T09:52:59.013 に答える