Re: DOM to SAX InputSource

Prasanna Kumar AG <[email protected]> Tue, 18 Feb 2003 01:42:19 -0500
Newsgroups gmane.comp.java.sun.xml.general
Message-ID <CB8215AD270F3F4B82E6B04F567C0AC4065417@eipmailsvr.erunway.atc.dns>
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
 <mailto:[email protected]> [email protected]
<mailto:[email protected]>
www.virtusa.com <http://www.virtusa.com/>