saxon-he报错

1.最近在做java爬虫,使用的是webmagic框架,为了使用xpath2.0的语法引入了webmagic-saxon的依赖,导致出现报错:

           java.lang.RuntimeException: XPathFactory#newInstance() failed to.....Illegal config


2.找到报错的代码是webmagic-saxon引入的saxon-he中的配置文件报错

<dependency>
  <groupId>net.sf.saxon</groupId>
  <artifactId>Saxon-HE</artifactId>
  <version>9.5.1-1</version>
  </dependency>
3.原因:

google了很长时间终于找到答案

由于这个版本的saxon-he (9.5.1)中配置文件的格式不被jdk8接收。

JDK 6和JDK 7接受了非法复合格式;;JDK 8不再接受这种格式。

而我使用的正式jdk1.8

4.解决方案

使用saxon-he的最新版本

就我使用webmagic-saxon而言,首先在webmagic-saxon中去除Saxon-HE,然后再添加Saxon-HE最新版本的依赖


<!-- 支持xpath2.0语法 -->
<dependency>
 <groupId>us.codecraft</groupId>
 <artifactId>webmagic-saxon</artifactId>
 <version>0.6.1</version>
 <exclusions>
  <exclusion>
   <groupId>net.sf.saxon</groupId>
   <artifactId>Saxon-HE</artifactId>
  </exclusion>
 </exclusions>

</dependency>




<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
 <groupId>net.sf.saxon</groupId>
 <artifactId>Saxon-HE</artifactId>
 <version>9.7.0-15</version>
</dependency>


这个网站可以搜dependency: http://mvnrepository.com/artifact/org.apache.httpcomponents




<?xml version=“1.0”encoding=“UTF-8”?><xsl:stylesheet version=“3.0”xmlns:xsl=“http:xmlns:fo=“http:xmlns:w=“http:exclude-result-prefixes=“w”><!--增强字体映射--><xsl:variable name="font-mapping"><font w:name="宋体"fo:name="SimSun"/><font w:name="黑体"fo:name="SimHei"/><font w:name="等线"fo:name="DengXian"/></xsl:variable><!--根模板--><xsl:template match="/"><fo:root><fo:layout-master-set><fo:simple-page-master master-name="A4"margin="1in"><fo:region-body margin-top="0.5in"margin-bottom="0.5in"/><fo:region-before extent="0.5in"/><fo:region-after extent="0.5in"/></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="A4"><fo:flow flow-name="xsl-region-body"><xsl:apply-templates select="//w:body/*"/></fo:flow></fo:page-sequence></fo:root></xsl:template><!--增强段落处理--><xsl:template match="w:p"><fo:block xsl:use-attribute-sets="paragraph-style"><xsl:apply-templates select="w:pPr/w:jc"mode="align"/><xsl:apply-templates select="w:pPr/w:ind"/><xsl:apply-templates select=".//w:r"/></fo:block></xsl:template><!--文本格式处理增强--><xsl:template match="w:r"><fo:inline><xsl:apply-templates select="w:rPr"/><xsl:value-of select="string-join(w:t, '')"/></fo:inline></xsl:template><!--增强字体处理--><xsl:template match="w:rPr"><xsl:variable name="w-font"select="w:rFonts/@w:ascii | w:rFonts/@w:hAnsi"/><xsl:attribute name="font-family"><xsl:value-of select="($font-mapping/font[@w:name = $w-font]/@fo:name, $w-font, 'SimSun')[1]"/></xsl:attribute><xsl:if test="w:sz/@w:val"><xsl:attribute name="font-size"select="w:sz/@w:val * 0.5 || 'pt'"/></xsl:if><xsl:if test="w:color/@w:val != 'auto'"><xsl:attribute name="color"select="'#' || w:color/@w:val"/></xsl:if><xsl:apply-templates select="w:b | w:i | w:u | w:strike"/></xsl:template><!--下划线和删除线处理--><xsl:template match="w:u"><xsl:attribute name="text-decoration">underline</xsl:attribute></xsl:template><xsl:template match="w:strike"><xsl:attribute name="text-decoration">line-through</xsl:attribute></xsl:template><!--表格处理增强--><xsl:template match="w:tbl"><fo:table table-layout="fixed"width="100%"><xsl:for-each select="w:tblGrid/w:gridCol"><fo:table-column column-width="{@w:w div 20}pt"/></xsl:for-each><fo:table-body><xsl:apply-templates select="w:tr"/></fo:table-body></fo:table></xsl:template><xsl:template match="w:tr"><fo:table-row><xsl:apply-templates select="w:tc"/></fo:table-row></xsl:template><xsl:template match="w:tc"><fo:table-cell border="1pt solid #000"padding="4pt"><fo:block><xsl:apply-templates select=".//w:p"/></fo:block></fo:table-cell></xsl:template><!--段落对齐处理--><xsl:template match="w:jc"mode="align"><xsl:attribute name="text-align"><xsl:choose><xsl:when test="@w:val = 'center'">center</xsl:when><xsl:when test="@w:val = 'right'">end</xsl:when><xsl:when test="@w:val = 'both'">justify</xsl:when><xsl:otherwise>start</xsl:otherwise></xsl:choose></xsl:attribute></xsl:template><!--段落缩进处理--><xsl:template match="w:ind"><xsl:attribute name="text-indent"><xsl:value-of select="@w:firstLine div 20 || 'pt'"/></xsl:attribute></xsl:template><!--增强段落样式--><xsl:attribute-set name="paragraph-style"><xsl:attribute name="space-after">12pt</xsl:attribute><xsl:attribute name="line-height">1.5</xsl:attribute><xsl:attribute name="text-align">left</xsl:attribute></xsl:attribute-set></xsl:stylesheet>这个不对,xsl:attribute没有select属性
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值