TransformerFactory.newInstance()。newTransformer(streamSource)返回null [英] TransformerFactory.newInstance().newTransformer(streamSource) returns null
问题描述
这怎么可能是TransformerFactory.newInstance()。newTransformer(streamSource)返回null。根据javadoc,这是不可能的:
http://download.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)
这里是groovy代码示例
def is = new ClassPathResource('xslt / MySpace-Contact.xsl')。inputStream
println是
def streamSource = new StreamSource(是)
println streamSource
def factory = TransformerFactory.newInstance( )
println factory
def tr = factory.newTransformer(streamSource)
println tr
以下是输出:
- 来自testTransformation的输出 -
java.io.BufferedInputStream @ 32999f10
javax.xml.transform.stream.StreamSource@399ed64
org.apache.xalan.processor .TransformerFactoryImpl @ 6eb04214
null
回答我自己的问题。如果XSLT文件无效,会发生(newTransformer(Source)将返回 null
)。我认为应该向Oracle报告,以便他们更改javadoc。返回 null
仍然是可能的。
How could that be that TransformerFactory.newInstance().newTransformer(streamSource) returns null. According to javadoc this is not possible: http://download.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)
here's groovy code sample
def is = new ClassPathResource('xslt/MySpace-Contact.xsl').inputStream
println is
def streamSource = new StreamSource(is)
println streamSource
def factory = TransformerFactory.newInstance()
println factory
def tr = factory.newTransformer(streamSource)
println tr
Here's the output:
--Output from testTransformation--
java.io.BufferedInputStream@32999f10
javax.xml.transform.stream.StreamSource@399ed64
org.apache.xalan.processor.TransformerFactoryImpl@6eb04214
null
Answering my own question. If XSLT file is not valid, that will happen (newTransformer(Source) will return null
). I think that should be reported to Oracle so they change the javadoc. It's still POSSIBLE that null
is returned.
这篇关于TransformerFactory.newInstance()。newTransformer(streamSource)返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!