result to a source 2003-04-09 - By Foxy Shadis
Result result = new StreamResult(new StringWriter()); ... Source source = new StreamSource(new StringReader(result.getWriter().toString())); -- Let me know if anything along those lines helps. I have no idea what kind of buffering StringWriter uses, so you may want to wrap it in a buffered writer.
My preferred method is this: -- StringWriter result = new StringWriter(); ... transformer.transform(xmlSource, new StreamResult(result)); ... Source source = new StreamSource(new StringReader(result.toString())); -- Which is roughly equivalent but easier for me to work with.
Swiftpaw Foxyshadis, wildlife artist foxyshadis@(protected) | http://foxyshadis.dyndns.org/
>From: Simon Kitching <simon@(protected)> > >I expect that you could use a DOMResult, then get the root node of the >resulting DOM, and wrap a DOMSource around it: > >DOMResult result = new DOMResult(); >transformer.transform(source, result); > >return new DOMSource(result.getNode()); > > >On Wed, 2003-04-09 at 22:44, Andrew Welch wrote: > > Hi, > > > > Sorry if this is a faq... > > > > I have a custom uri resolver that I want to do a transform before >passing the result back to the requesting stylesheet. How do I go from a >result to a source? I can write the result out and then read it back in, >says as a string or bytes, but this seems unecessary... my knowledge of >streams is really lacking :( > > > > code sample: > > > > public Source resolve(String href, String base) throws >TransformerException { > > try { > > URL context = new URL("file:///"); > > URL u = new URL(context, href); > > > > InputStream is = new FileInputStream(u.toString()); > > > > TransformerFactory tf = TransformerFactory.newInstance(); > > Source xsl = new StreamSource(new >File("C:\\test\\AddElementIdToStylesheet.xsl")); > > > > Result result = new StreamResult(???); > > ^^^what type of result do I need here? > > > > Transformer transformer = tf.newTransformer(xsl); > > transformer.transform(new StreamSource(is, u.toString()), result); > > > > return ????; > > ^^^how do I return the result as a source? > > } catch (Exception ex) { > > System.out.println(ex.toString()); > > ex.printStackTrace(); > > } > > return null; > > } > > > > cheers > > andrew > >
_________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
|
|