[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: TransformerHandler Chaining with Java and Saxon

Subject: RE: TransformerHandler Chaining with Java and Saxon
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 3 Jun 2009 00:13:58 +0100
RE:  TransformerHandler Chaining with Java and Saxon
Could be this bug

https://sourceforge.net/tracker/index.php?func=detail&aid=1558231&group_id=2
9872&atid=397617

though that's documented as applying to 8.8 rather than 8.9.

Another candidate is this one, in 9.0

https://sourceforge.net/tracker/?func=detail&aid=1986836&group_id=29872&atid
=397617

I suggest you try it on a more recent release. The current release is
9.1.0.6.

Also, I suggest you raise Saxon-specific problems on the saxon-help list at
SourceForge.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: Scott Lynch [mailto:slynch@xxxxxxxxxx] 
> Sent: 02 June 2009 23:50
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  TransformerHandler Chaining with Java and Saxon
> 
> All,
> 
> This is not quite an xsl question, but hopefully someone here 
> has seen this before and can help me, because I've been 
> banging my head on my keyboard for hours now. I'm trying to 
> chain together several transforms using the 
> TransformerHandler chaining design pattern in Java with the 
> Saxon (8.9) engine. The code below invariable throws an 
> exception complaining about "The TransformerHandler is not 
> serially reusable. The
> startDocument() method must be called once only." when the
> reader.parse(source) method is invoked. 
> 
> Does anyone know why this would be happening and how to 
> prevent it? I am able to individually transform my file with 
> the transforms by using a set of rotating temporary files, 
> but I would like to increase the speed of the transformation 
> (I'm transforming about 17 files comprising 50meg of data 
> through about 10 transforms and this is taking several 
> minutes) using chaining if possible.
> 
> thanks,
> Scott
> 
> 
>     private String multiTransform(String sourceFileName, 
> List<String> transformFiles, String startKey)
>     {
>         String outFileName = "transformOutput.xml";
>         try
>         {
>             TransformerFactory factory = 
> TransformerFactory.newInstance();
>             SAXTransformerFactory saxTFactory = 
> ((SAXTransformerFactory) factory);
>             List<TransformerHandler> handlers = new 
> ArrayList<TransformerHandler>();
>             TransformerHandler previousHandler = null;
>             for (String transformFile : transformFiles)
>             {
>                 StreamSource source = new 
> StreamSource(Resources.getResource(transformFile).openStream());
>                 TransformerHandler handler = 
> saxTFactory.newTransformerHandler(source);
>                 handlers.add(handler);
>                 if (previousHandler != null)
>                 {
>                     previousHandler.setResult(new SAXResult(handler));
>                     break;
>                 }
>                 previousHandler = handler;
>             }
> 
>             XMLReader reader = XMLReaderFactory.createXMLReader();
>             reader.setContentHandler(handlers.get(0));
> 
>             TransformerHandler lastHandler =
> handlers.get(handlers.size() - 1);
>             OutputStream resultOutStream = new 
> FileOutputStream(outFileName);
>             StreamResult xformOutResult = new 
> StreamResult(resultOutStream);
>             lastHandler.setResult(xformOutResult);
>             FileInputStream fileInStrm = new 
> FileInputStream(sourceFileName);
>             InputSource source = new InputSource(fileInStrm);
>             reader.parse(source);
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         }
>         return outFileName;
>     }
> 
> 
> 
> The exception...
> 
> java.lang.UnsupportedOperationException: The 
> TransformerHandler is not serially reusable. The 
> startDocument() method must be called once only.
> 	at
> net.sf.saxon.TransformerHandlerImpl.startDocument(TransformerH
> andlerImpl
> .java:69)
> 	at
> net.sf.saxon.event.ContentHandlerProxy.open(ContentHandlerProx
> y.java:242
> )
> 	at net.sf.saxon.event.ProxyReceiver.open(ProxyReceiver.java:76)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.open(ImplicitResultCh
> ecker.java
> :24)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.firstContent(Implicit
> ResultChec
> ker.java:59)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.startElement(Implicit
> ResultChec
> ker.java:30)
> 	at
> net.sf.saxon.event.NamespaceReducer.startElement(NamespaceRedu
> cer.java:5
> 4)
> 	at
> net.sf.saxon.event.ComplexContentOutputter.startContent(Comple
> xContentOu
> tputter.java:481)
> 	at
> net.sf.saxon.event.ComplexContentOutputter.characters(ComplexC
> ontentOutp
> utter.java:136)
> 	at net.sf.saxon.instruct.Copy.processLeavingTail(Copy.java:164)
> 	at
> net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
> 	at
> net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:99)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 319)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:189)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.process(ApplyTemplates.java:149)
> 	at
> net.sf.saxon.instruct.ElementCreator.processLeavingTail(Elemen
> tCreator.j
> ava:250)
> 	at net.sf.saxon.instruct.Copy.processLeavingTail(Copy.java:152)
> 	at
> net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
> 	at
> net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:99)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 319)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTempla
> tes.java:3
> 51)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 312)
> 	at
> net.sf.saxon.Controller.transformDocument(Controller.java:1602)
> 	at
> net.sf.saxon.TransformerHandlerImpl.endDocument(TransformerHan
> dlerImpl.j
> ava:133)
> 	at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.e
> ndDocument
> (AbstractSAXParser.java:737)
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentSca
> nnerImpl.s
> canDocument(XMLDocumentFragmentScannerImpl.java:515)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.
> parse(XML1
> 1Configuration.java:807)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.
> parse(XML1
> 1Configuration.java:737)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XML
> Parser.jav
> a:107)
> 	at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.p
> arse(Abstr
> actSAXParser.java:1205)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.