File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How get InputSource or InputStream from org.w3c.dom.Document? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How get InputSource or InputStream from org.w3c.dom.Document?" Watch "How get InputSource or InputStream from org.w3c.dom.Document?" New topic
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
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
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: 18987
    
    8

Basavaraj Malagi,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How get InputSource or InputStream from org.w3c.dom.Document?