我在 XSLT 撒克逊解析器中遇到异常
I am getting exception in XSLT saxon parser
我为 saxen 解析器添加了一个 Maven 依赖项,然后将 xml 和 xsl 作为字符串参数发送到 saxonTransform(String xml, String xsl)。但是出现了一些异常。
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.6</version>
</dependency>
撒克逊变形金刚(XSLT)代码:
public static String saxonTransform(String xml, String xsl) throws TransformerException, FileNotFoundException {
String result = "";
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
StringWriter out = new StringWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
tFactory.setAttribute(FeatureKeys.DTD_VALIDATION, false);
StreamSource xmlSource = new StreamSource(new StringReader(xml));
StreamSource xslSource = new StreamSource(new StringReader(xsl));
StreamResult xmlResult = new StreamResult(out);
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, xmlResult);
result = out.toString();
return result;
}
但是,给定的行无法转换 xml:
Transformer transformer = tFactory.newTransformer(xslSource);
给出如下错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Handler dispatch failed; nested exception is javax.xml.parsers.FactoryConfigurationError:
Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found] with root cause
在这一行
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
你说你想使用 Apache Xerces 作为你的 XML 解析器,但看起来它在类路径上不可用。
(请注意,如今对于大多数用途而言,使用 JDK 中内置的 Xerces 版本效果非常好。曾经有一段时间 JDK 版本存在一些严重的错误,但是这似乎已经修复了一段时间。)
我为 saxen 解析器添加了一个 Maven 依赖项,然后将 xml 和 xsl 作为字符串参数发送到 saxonTransform(String xml, String xsl)。但是出现了一些异常。
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>10.6</version>
</dependency>
撒克逊变形金刚(XSLT)代码:
public static String saxonTransform(String xml, String xsl) throws TransformerException, FileNotFoundException {
String result = "";
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
StringWriter out = new StringWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
tFactory.setAttribute(FeatureKeys.DTD_VALIDATION, false);
StreamSource xmlSource = new StreamSource(new StringReader(xml));
StreamSource xslSource = new StreamSource(new StringReader(xsl));
StreamResult xmlResult = new StreamResult(out);
Transformer transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, xmlResult);
result = out.toString();
return result;
}
但是,给定的行无法转换 xml:
Transformer transformer = tFactory.newTransformer(xslSource);
给出如下错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Handler dispatch failed; nested exception is javax.xml.parsers.FactoryConfigurationError:
Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found] with root cause
在这一行
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl");
你说你想使用 Apache Xerces 作为你的 XML 解析器,但看起来它在类路径上不可用。
(请注意,如今对于大多数用途而言,使用 JDK 中内置的 Xerces 版本效果非常好。曾经有一段时间 JDK 版本存在一些严重的错误,但是这似乎已经修复了一段时间。)