感谢您审核我的问题。
我使用saxon java api作为XSLT处理器。难以通过saxon jar文件捕获异常返回。
我可以打印javax异常。但需要在saxon返回的字符串中获取异常。
我正在使用的函数转换xml:
import java.io.File;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
/**
* Simple transformation method.
* @param sourcePath - Absolute path to source xml file.
* @param xsltPath - Absolute path to xslt file.
* @param resultDir - Directory where you want to put resulting files.
*/
public static void simpleTransform(String sourcePath, String xsltPath,
String resultDir) {
TransformerFactory tFactory = TransformerFactory.newInstance();
try {
Transformer transformer =
tFactory.newTransformer(new StreamSource(new File(xsltPath)));
transformer.transform(new StreamSource(new File(sourcePath)),
new StreamResult(new File(resultDir)));
} catch (Exception e) {
e.message();
}
}
public static void main(String[] args) {
//Set saxon as transformer.
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
simpleTransform("d:/project/hob/AppModule.xml",
"d:/project/hob/create-fragment.xslt", "C:/");
}
}
你们可以建议将saxon异常放入字符串中。下面是异常返回的saxon jar文件的示例。
SXJE0008:无法将xs:yearMonthDuration转换为所需的Java类型
谢谢, 迪帕克