Hi,
 
This is not very efficient though (you're serializing the document to a string first, right?). I think there's a class somewhere in GNU that generates SAX events directly from a DOM document. Another place to look would be �lfred. I remember reading about this in O'Reilly's SAX2 book, which I'd recommend buying.
A quick search on Google yields the following link too: http://xml.apache.org/xalan-j/apidocs/org/apache/xalan/xsltc/trax/DOM2SAX.html
 
Cheers,
Alex
-----Original Message-----
From: Prasanna Kumar AG [mailto:[EMAIL PROTECTED]
Sent: February 17, 2003 10:42 PM
To: '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'
Subject: RE: DOM to SAX InputSource

Ok! Got a Solution!
Used StringWriter to hold the XML DOM tree and used it as input to SAX InputSource.
 
      DOMSource objXMLSource = new DOMSource(sourceDocument);
      StringWriter stringOut = new StringWriter();
      StreamResult objResultStream = new StreamResult(stringOut);
      Transformer objTransformer = TransformerFactory.newInstance().newTransformer();
      objTransformer.transform(objXMLSource, objResultStream);
      String xmlString = stringOut.toString();
      ByteArrayInputStream stream =    new ByteArrayInputStream(xmlString.getBytes());
      InputSource is = new InputSource(stream);
 
Regards
Prasanna Kumar

-----Original Message-----
From: Prasanna Kumar AG [mailto:[EMAIL PROTECTED]
Sent: Friday, February 14, 2003 5:00 PM
To: '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'
Subject: DOM to SAX InputSource

Hi All,
Is there any way by which I can generate SAX InputSource from a org.w3c.dom.Document object, without generating temporary XML file.
I am using iText library to generate PDF from an XML source. As an XML Source I have a Document object. But the iText library only supports input in the form of  SAX InputSource.
 
Any suggestions?
 
Thanks,
Prasanna Kumar
Virtusa India Pvt. Ltd.,
Phone : (+91)-40-3414200 ext 220
[EMAIL PROTECTED]
www.virtusa.com
 

Reply via email to