how to create an InputStream from a Document or Node

前端 未结 5 375
后悔当初
后悔当初 2021-01-03 20:35

How can I create an InputStream object from a XML Document or Node object to be used in xstream? I need to replace the ??? with some meaningful code. Thanks.



        
5条回答
  •  离开以前
    2021-01-03 20:59

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Source xmlSource = new DOMSource(doc);
    Result outputTarget = new StreamResult(outputStream);
    TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
    InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
    

提交回复
热议问题