Author
How get InputSource or InputStream from org.w3c.dom.Document?
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
I have an org.w3c.dom.Document object that was altered in a method. Now I want to pass it to another method that can only take an InputSource or InputStream . Does anyone know how I can do this?
Billybob Marshall
Ranch Hand
Joined: Jan 27, 2004
Posts: 202
posted Feb 04, 2004 11:51:00
0
import javax.xml.transform.dom.DOMSource ; import javax.xml.transform.stream.StreamResult ; import javax.xml.transform.TransformerFactory ; Document doc = ... // your existing DOM document DOMSource source = new DOMSource (doc); StringWriter xmlAsWriter = new StringWriter (); StreamResult result = new StreamResult (xmlAsWriter); TransformerFactory.newInstance().newTransformer().transform(source, result); StringReader xmlReader = new StringReader (xmlAsWriter.toString()); InputSource viola = new InputSource (xmlReader);
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
thanks!
Billybob Marshall
Ranch Hand
Joined: Jan 27, 2004
Posts: 202
posted Feb 04, 2004 12:21:00
0
you're welcome
Igor Jacy Lino Campista
Greenhorn
Joined: May 30, 2009
Posts: 1
For the InputStream you can use:
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16479
Basavaraj Malagi, Your post was moved to a new topic .
subject: How get InputSource or InputStream from org.w3c.dom.Document?