我在Transformer transformer = tFactory.newTransformer(StreamXSL);
上遇到异常但是下面的错误并不明确我无法理解为什么“无法编译样式表”?
韩国社交协会
static String getHtml(String xml)
{
Element elementObj = getElementObject(xml);
String xslName = getValueOfElement(elementObj, xml, "XSL_TO_RUN");
StreamSource StreamXML = new StreamSource(new StringReader(xml));
try{
TransformerFactory tFactory = TransformerFactory.newInstance();
if(xslName!=null){
String xslfile = xslName;
File xfile = new File(xslfile);
if (xfile.exists()){}
else
{
LogI.log(4,"getHtml:: ERROR: xsl file don´t Exist! " + xslName );
return null;
}
StreamSource StreamXSL = new StreamSource(xfile);
Transformer transformer = tFactory.newTransformer(StreamXSL);
}else{
LogI.log(0,"getHtml::ERROR->Error on create stream XSL");
return null;
}
} catch(TransformerConfigurationException ex){
LogI.log(0,"getHtml::Erro crossing the XML with the XSL:" + ex);
LogI.log(0,"getHtml::Erro crossing the XML with the XSL(1):" + ex.getMessageAndLocation());
LogI.log(0,"getHtml::Erro crossing the XML with the XSL(2):" + ex.getMessage());
for(int i=0;i<ex.getStackTrace().length;i++){
LogI.log(0, "ARQ::Pedido:: ERRO(2) ->" + ex.getStackTrace()[i]);
}
return null;
} catch(Exception e){
LogI.log(0,"getHtml::Erro crossing the XML with the XSL:" + e);
//out.clear();
//out.println(errorPage);
return null;
}
}
这是输出:
ERRO: getHtml::Erro crossing the XML with the XSL:javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
ERRO: getHtml::Erro crossing the XML with the XSL(1):Could not compile stylesheet
ERRO: getHtml::Erro crossing the XML with the XSL(2):Could not compile stylesheet
ERRO: ARQ::Pedido:: ERRO(2) ->com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source)
ERRO: ARQ::Pedido:: ERRO(2) ->com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source)
ERRO: ARQ::Pedido:: ERRO(2) ->BizBanc.Arq.getHtml(Arq.java:189)
ERRO: ARQ::Pedido:: ERRO(2) ->BizBanc.Arq.getResponse(Arq.java:792)
答案 0 :(得分:0)
您的输出显示您获得了TransformerConfigurationException
;根据[API](http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)),这些是
“如果在解析Source时出现错误或者无法创建Transformer实例,则抛出该异常。”
您的语法似乎没问题,所以我怀疑您的文件导致问题。我看到你正在检查确保文件存在,但你确定它的内容没问题吗?