RE: Converting Document object (DOM) into inputsource for XS
The better approach is to use John Cowan's DOMParser (http://www.ccil.org/~cowan/XML/) (* thanks for the link Michael) InputSource domSource = new org.ccil.cowan.sax.DOMSource(yourDocument); Parser inputParser = new org.ccil.cowan.sax.DOMParser(); Parser sheetParser = "... your favorite XML parser ..."; XSLProcessorImpl xt = new XSLProcessorImpl(); xt.setParser(inputParser, sheetParser); xt.parse(domSource); This will avoid the unnecessary 'flattening' and parsing. > Do you mean that for small document (less than 10Kb), it's faster to > transform DOM into byte and then reparse it ? Did I understand > well? Flattening the DOM tree onto bytes and reparsing it will always be costly, what Dan was suggesting was to 'pipe' : (1) DOM -> DOMWriter -> InputStreamWriter -> PipedOutputStream -> PipedInputStream -> SAXParser instead of : (2) flattening : DOM -> DOMWriter -> InputStreamWriter -> byte and then inflating : byte -> ByteArrayInputStream -> SAXParser in two separate steps. (1) has the advantage of being memory efficient (the memory usage is the size of the PipedInputStream's buffer). The overhead of (1) is that there is a that the threads are 'waiting' and 'notifying' a lot, but for big enough documents (2) will bust your memory. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format