Using transform() with InputSource object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baskarpr
    New Member
    • Oct 2006
    • 33

    #1

    Using transform() with InputSource object

    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 :

    Code:
    DocumentBuilderFactory dbfac1 = DocumentBuilderFactory
                        .newInstance();
    DocumentBuilder dbparser1 = dbfac1.newDocumentBuilder();
    Document doc1 = dbparser1.parse(new File("source.xml"));
    DOMSource dm1 = new DOMSource(doc1);            
    InputSource ss1 = SAXSource.sourceToInputSource(dm1);
     
    // This is the usual way of transform(). Instead of using DOMSource
    // as argument, somehow I have to incorporate InputSource obj 
    // created above i.e. ss1.
     
    SAXTransformerFactory stf1 = (SAXTransformerFactory) 
    SAXTransformerFactory.newInstance();            
    Transformer t1 = stf1.newTransformer();
    t1.transform(dm1,new StreamResult(new 
                        FileOutputStream(output1)));
    Thanks in advance..
  • rengaraj
    New Member
    • Jan 2007
    • 168

    #2
    Assuming that InputSource is org.xml.sax.Inp utSource then there is a method getByteStream() on InputSource so all you need to do is
    t1.transform(dm 1, new StreamResult(ss l.getByteStream ()));

    Comment

    Working...