how to create an InputStream from a Document or Node

前端 未结 5 374
后悔当初
后悔当初 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:44

    One way to do it: Adapt the Document to a Source with DOMSource. Create a StreamResult to adapt a ByteArrayOutputStream. Use a Transformer from TransformerFactory.newTransformer to copy across the data. Retrieve your byte[] and stream with ByteArrayInputStream.

    Putting the code together is left as an exercise.

提交回复
热议问题