XML data from java class to transformer...help!

Discussions

XML & Web services: XML data from java class to transformer...help!

  1. XML data from java class to transformer...help! (2 messages)

    I have an java class that stores XML data using the org.w3c.dom classes. I've given it a .writeXML(java.io.Writer) method to write its data (using org.apache.xml.serialize.XMLSerializer). The problem comes when I want to pass this data to an XSLT transformer, which needs a StreamSource (created with a Reader, not a Writer obviously). What I tried (and failed) to do was use a PipedReader and PipedWriter, linked together. The XML data would be written to the PipedWriter, I'd call .close() on it, and the data would then be available to the PipedReader and thus the transoformer. The problem is that PipedReaders/Writers weren't meant to be used this way, and there is a 1k buffer limit that I cannot get around. In other words, this technique works so long as the amount of XML data is under 1k. But that isn't acceptable. I was thinking that this must surely be a common problem, and surely someone has found a way to accomplish this. Any help would be greatly appreciated.
  2. Use a DomSource (javax.xml.transform.dom.DOMSource) object passing it the dom structure that your object already stores.

  3. Follow the advice in the last post, but if you should for some reason in the future need to convert a Reader or Writer to a String, you can use StringReader, StringWriter.