Subject: Re: Converting Document object (DOM) into inputsource for XSL process ing in XT From: "Dan Machak" <machak@xxxxxxxxxxxx> Date: Thu, 26 Aug 1999 09:29:11 -0700 |
On Aug 26, 4:29pm, Sebastien Sahuc wrote: > ... > > ByteArrayOutputStream docOutputStream = new ByteArrayOutputStream(); > ((XmlDocument)myDOMDocument).write(docOutputStream); > ByteArrayInputStream docInputStream = new > ByteArrayInputStream(docOutputStream.toByteArray()); > InputSource inputSource = new InputSource(docInputStream); > myXslProcessor.parse(inputSource); > > Is there a better way to handle these opreations, since they're time > consuming in resource and memory. Have you looked at using the PipedInputStream and PipedOutputStream combination? To gain the advantage, you would need to have two Threads. The first thread would create a PipedOutputStream and write your DOM document to the stream. The second thread would create a PipedInputStream, using the previously created PipedOutputStream in the constructor. The advantage is you avoid having to convert the whole DOM tree to a byte array before sending it off to the the XSL processor. With the piped streams, the XSL processor could start processing the XML before the DOM tree is fully converted. What I don't know is if the overhead of spawning a new Thread is worse than creating the byte arrary. As the file gets larger however, the piped streams would have more of an advantage. The code would look something like this. PipedOutputStream pipeOut = new PipedOutputStream(); DOMWriter dw = new DOMWriter(pipeOut, (XmlDocument)myDOMDocument); dw.start(); PipedInputStream pipeIn = new PipedInputStream(pipeOut); InputSource inputSource = new InputSource(pipeIn); myXslProcessor.parse(inputSource); public class DOMwriter extends Thread { OutputStream mOut; XmlDocument mDoc; DOMwriter(OutputStream out, XmlDocument doc) { mOut = out; mDoc = doc; } public void run() { mDoc.write(mOut); } } > > Beside this, I tried using DOM directly with XSL:P processor, but it > wasn't faster than XT solution, so I'm deducting that it take longer > to work with DOM that to parse again the XML document and then work > with it internal and lightweight representation, is it true ? > > Thank for any reply, I would really appreciate. > > Sebastien Sahuc > ssahuc@xxxxxxxxxxxxxx > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list >-- End of excerpt from Sebastien Sahuc Dan -- <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> <> Dan Machak <> machak@xxxxxxxxxxxx <> <> MS T27A-1 <> 650-604-2388 (VOICE) <> <> NASA Ames Research Center <> 650-604-3957 (FAX) <> <> Moffett Field, CA 94035-1000 <> <> <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Converting Document object (DOM) in, Sebastien Sahuc | Thread | RE: Converting Document object (DOM, Maxime Levesque |
RE: Help with lots of <'s, Mike Brown | Date | Re: Help with lots of <'s, David Carlisle |
Month |