how to marshal a JAXB object to org.w3c.dom.Document?

后端 未结 2 1914
别那么骄傲
别那么骄傲 2020-12-14 20:11

This gives me a Document object with a top level node with no child nodes:

public static Document getDocument(Object jaxb)
{
    DocumentBuilderFactory dbf =         


        
2条回答
  •  再見小時候
    2020-12-14 20:26

    try this

        DOMResult res = new DOMResult();
        JAXBContext context = JAXBContext.newInstance(obj.getClass());
        context.createMarshaller().marshal(obj, res);
        Document doc = (Document) res.getNode();
    

提交回复
热议问题