Project

Profile

Help

ClassCastException using DOMSource

Added by Anonymous almost 16 years ago

Legacy ID: #5155506 Legacy Poster: Kevan Simpson (kevan1138)

Running a simple XSL transformation which succeeds or fails depending on the type of javax.xml.transform.Source used as input to the transformation. The basic scenario (with abbreviated code) follows: Processor proc = new Processor(false); XsltCompiler comp = proc.newXsltCompiler(); XsltExecutable exec = comp.compile(new StreamSource(new File("some/path/bug.xsl"))); XsltTransformer xsl = exec.load(); xsl.setSource( /* this is where the problem is... see below */); StringWriter writer = new StringWriter(); Serializer out = new Serializer(); out.setOutputWriter(writer); xsl.setDestination(out); // compare writer.toString() to expected output Calling setSource() works when passing in a StreamSource or a DOMSource created with a org.w3c.Document, but it fails when a DOMSource created with the document's DocumentElement is passed in. The failure stacktrace is: java.lang.ClassCastException: net.sf.saxon.tinytree.TinyElementImpl at net.sf.saxon.Configuration.buildDocument(Configuration.java:2977) at net.sf.saxon.s9api.DocumentBuilder.build(DocumentBuilder.java:287) at net.sf.saxon.s9api.XsltTransformer.setSource(XsltTransformer.java:108) at SaxonBug.main(SaxonBug.java:76) I have a test class which is reproducible, available upon request or if a bug should be filed. Please advise.


Replies (2)

RE: ClassCastException using DOMSource - Added by Anonymous almost 16 years ago

Legacy ID: #5155602 Legacy Poster: Michael Kay (mhkay)

Thanks for reporting this. I've reproduced the problem (which affects Configuration.buildDocument() as well as the s9api DocumentBuilder). It certainly shouldn't be throwing a ClassCastException. I'm not entirely sure what it should be doing: the Javadoc for Configuration.buildDocument() says clearly that it makes a copy of the DOM element as a new document and returns the document node, which isn't what is happening. The DocumentBuilder spec is less clear, but I think this should also be the behaviour here. WHat's less clear is that XsltTransformer.setSource() should be building a new document (rather than creating a wrapper) in this case. I'll look at this one in detail when I get back from vacation.

RE: ClassCastException using DOMSource - Added by Anonymous almost 16 years ago

Legacy ID: #5220395 Legacy Poster: Kevan Simpson (kevan1138)

Hi Michael, Any progress on this bug? And will there be an updated release with the fix? Thanks, Kevan

    (1-2/2)

    Please register to reply