By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

Using transform() with InputSource object

P: 33
Hi all,

I have created one InputSource object and using that object I have transform the Source into result. The code I used is below :

Expand|Select|Wrap|Line Numbers
  1. DocumentBuilderFactory dbfac1 = DocumentBuilderFactory
  2.                     .newInstance();
  3. DocumentBuilder dbparser1 = dbfac1.newDocumentBuilder();
  4. Document doc1 = dbparser1.parse(new File("source.xml"));
  5. DOMSource dm1 = new DOMSource(doc1);            
  6. InputSource ss1 = SAXSource.sourceToInputSource(dm1);
  7.  
  8. // This is the usual way of transform(). Instead of using DOMSource
  9. // as argument, somehow I have to incorporate InputSource obj 
  10. // created above i.e. ss1.
  11.  
  12. SAXTransformerFactory stf1 = (SAXTransformerFactory) 
  13. SAXTransformerFactory.newInstance();            
  14. Transformer t1 = stf1.newTransformer();
  15. t1.transform(dm1,new StreamResult(new 
  16.                     FileOutputStream(output1)));
  17.  
Thanks in advance..
Jan 29 '07 #1
Share this Question
Share on Google+
1 Reply


100+
P: 168
Assuming that InputSource is org.xml.sax.InputSource then there is a method getByteStream() on InputSource so all you need to do is
t1.transform(dm1, new StreamResult(ssl.getByteStream()));
Feb 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.