最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】docbook中用ant编译webhelp时出错:[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href=’xxx.xml’).

Docbook crifan 2525浏览 0评论

【问题】

已有docbook源码,用ant编译webhelp,

对于之前错误的ENTITY的写法:

<!ENTITY % crl_ent PUBLIC "crl.ent" 'null'>%crl_ent;

为了使得尽量地让ant继续能够往下编译,所以通过删除了上面那句,而临时性地解决了ENTITY的null问题,(后来彻底解决了ENTITY的null问题,参见:【已解决】docbook中用ant编译webhelp时出错:[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: xxx\null (系统找不到指定的文件。),其也同时解决了当前问题。)

而使得ant编译可以继续,但是又出现错误:

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1910371317
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] : Error! Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] Failed to process E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml

BUILD FAILED
E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml:35: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:195)
        at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:853)
        at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:389)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:392)
        at org.apache.tools.ant.Target.performTasks(Target.java:413)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:811)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(Unknown Source)
        ... 22 more

即无法解析XML文件的错误:

[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href=’ch01_reduced_instruction_set.xml’).

【解决过程】

1.以后为xml的解析器有问题,所以后来参考:

Chapter 23. Modular DocBook files – Processing your modular documents

去把build.xml中的

	 <!--TagSoup SAX Parser for parsing even the bad html contents. see 
	      http://sourceforge.net/tracker/?func=detail&aid=3401185&group_id=21935&atid=373750-->
         <sysproperty key="org.xml.sax.driver" value="org.ccil.cowan.tagsoup.Parser"/>
         <sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl"/>

         <!-- Uncomment the following if Xerces is your preference as the SAX XML Parser. Note that the indexing will fail with Xerces
	      if the html files are not XML-conformance -->
  	 <!--sysproperty key="org.xml.sax.driver" value="org.apache.xerces.parsers.SAXParser"/>	      
         <sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/-->

改为:

	 <!--TagSoup SAX Parser for parsing even the bad html contents. see 
	      http://sourceforge.net/tracker/?func=detail&aid=3401185&group_id=21935&atid=373750-->
         <!--<sysproperty key="org.xml.sax.driver" value="org.ccil.cowan.tagsoup.Parser"/>
         <sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl"/>-->

         <!-- Uncomment the following if Xerces is your preference as the SAX XML Parser. Note that the indexing will fail with Xerces
	      if the html files are not XML-conformance -->
        <sysproperty key="org.xml.sax.driver"                   value="org.apache.xerces.parsers.SAXParser"/>
        <sysproperty key="javax.xml.parsers.SAXParserFactory"   value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
        <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration" value="org.apache.xerces.parsers.XIncludeParserConfiguration" />

结果错误依旧。

2.去

http://labs.mop.com/apache-mirror//xerces/j/

下载了新版的Xerces-J:Xerces-J-bin.2.11.0.tar.gz,解压后得到新版的xercesImpl.jar和xml-apis.jar,再去试试新版xerces的的效果如何,结果错误依旧。

3.后来想到了,应该去对照教程中的webhelp的例子中的xml源码,看看其xinclude是如何处理的。

然后就去看了看,原来最开始的那个webhelp例子中xml文件readme.xml中,最后有一行是:

  <!--<xi:include href="xinclude-test.xml"  xmlns:xi="http://www.w3.org/2001/XInclude"/>-->

然后就去取消注释,去编译试试。

结果好像可以运行,但是运行速度超慢,所以又去把xercesImpl.jar和xml-apis.jar改为旧的版本试试。

结果由于几次强制关于cygwin中正在运行的ant导致后来再运行不带xinclude的xml都还是会死掉,然后是由于发现进程中有几个之前未彻底关闭的java进程,就去强制关闭了。

以为这下可以正常关闭了,结果还是死在了这里:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp
$ ant webhelp -Doutput-dir=test-ouput
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\docsrc\readme.xml to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput\null1936611731
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput\null1936611731 to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput\null424473780
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing test-ouput/content/ch01.html for chapter
     [xslt] Writing test-ouput/content/ch02s01.html for section
     [xslt] Writing test-ouput/content/ch02s02.html for section
     [xslt] Writing test-ouput/content/ch02s03.html for section
     [xslt] Writing test-ouput/content/ch02s04.html for section
     [xslt] Writing test-ouput/content/ch02s05.html for section
     [xslt] Writing test-ouput/content/ch02.html for chapter
     [xslt] Writing test-ouput/content/ch03s01.html for section
     [xslt] Writing test-ouput/content/ch03s02.html for section
     [xslt] Writing test-ouput/content/ch03.html for chapter
     [xslt] Writing test-ouput/content/ch04.html for chapter
     [xslt] Writing test-ouput/content/index.html for book
     [xslt] Writing test-ouput/index.html
     [xslt] Writing test-ouput/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput
     [copy] Copying 2 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-ouput
     [echo] Indexing html files in test-ouput/content
     [java] Stemming enabled

然后就执行不下去了。

然后搜索"ant webhelp [java] Stemming enabled"却又找到了readme.xml,然后才发现,build.properties中有对应的配置选项:

# Enables/Disables stemming
# Stemming allows better querying for the search
enable.stemming=true

然后先去关闭试试。

(但很奇怪,之前是不需要关闭,就可以正常编译的)

结果再去运行,还是出错,最后死在:

[java] Stemming disabled

显然,这说明不是这个Stemming的问题。

而是之后的哪一步出了错。

4. 对比了一下之前的log:

[java] Stemming enabled
[java] The created index files are located in test-ouput\content\search\.js
[java] Delay = 1 seconds

webhelp:
BUILD SUCCESSFUL
Total time: 8 seconds

可以看出,是创建索引文件这部无法顺利执行了.

5.去对比一下,此刻docbook-xsl-ns-1.77.0的内容和原始的内容有何区别,是不是不小心改了哪里了,否则为何之前可以正常编译的,现在却不可以了.

果然,发现问题所在了:

sysproperty changed

即sysproperty被之前改掉了,我说怎么一直无法正常编译呢.

所以,都还原到最开始的设置,然后再去试试.

6.果然,这下就是可以正常的编译了:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp
$ ant webhelp -Doutput-dir=test-output
cygwin warning:
  MS-DOS style path detected: E:\dev_install_root\apache_ant\apache-ant-1.8.4
  Preferred POSIX equivalent is: /cygdrive/e/dev_install_root/apache_ant/apache-ant-1.8.4
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\docsrc\readme.xml to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null1828495645
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null1828495645 to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null567061876
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing test-output/content/ch01.html for chapter
     [xslt] Writing test-output/content/ch02s01.html for section
     [xslt] Writing test-output/content/ch02s02.html for section
     [xslt] Writing test-output/content/ch02s03.html for section
     [xslt] Writing test-output/content/ch02s04.html for section
     [xslt] Writing test-output/content/ch02s05.html for section
     [xslt] Writing test-output/content/ch02.html for chapter
     [xslt] Writing test-output/content/ch03s01.html for section
     [xslt] Writing test-output/content/ch03s02.html for section
     [xslt] Writing test-output/content/ch03.html for chapter
     [xslt] Writing test-output/content/ch04.html for chapter
     [xslt] Writing test-output/content/index.html for book
     [xslt] Writing test-output/index.html
     [xslt] Writing test-output/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 2 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [echo] Indexing html files in test-output/content
     [java] Stemming disabled
     [java] The created index files are located in test-output\content\search\.js
     [java] Delay = 681 milliseconds

webhelp:

BUILD SUCCESSFUL
Total time: 4 seconds

7. 然后再去readme.xml中,加上:

<xi:include href="xinclude-test.xml"  xmlns:xi="http://www.w3.org/2001/XInclude"/>

然后试试,结果是,其也出现我之前就遇到的问题:

[xslt] Element include in namespace ‘http://www.w3.org/2001/XInclude’ encountered in book, but no template matches.

完整log如下:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp
$ ant webhelp -Doutput-dir=test-output
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\docsrc\readme.xml to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null457493846
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null457493846 to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null613463135
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing test-output/content/ch01.html for chapter
     [xslt] Writing test-output/content/ch02s01.html for section
     [xslt] Writing test-output/content/ch02s02.html for section
     [xslt] Writing test-output/content/ch02s03.html for section
     [xslt] Writing test-output/content/ch02s04.html for section
     [xslt] Writing test-output/content/ch02s05.html for section
     [xslt] Writing test-output/content/ch02.html for chapter
     [xslt] Writing test-output/content/ch03s01.html for section
     [xslt] Writing test-output/content/ch03s02.html for section
     [xslt] Writing test-output/content/ch03.html for chapter
     [xslt] Writing test-output/content/ch04.html for chapter
     [xslt] Element include in namespace 'http://www.w3.org/2001/XInclude' encountered in book, but no template matches.
     [xslt] Writing test-output/content/index.html for book
     [xslt] Writing test-output/index.html
     [xslt] Writing test-output/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 2 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [echo] Indexing html files in test-output/content
     [java] Stemming disabled
     [java] The created index files are located in test-output\content\search\.js
     [java] Delay = 674 milliseconds

webhelp:

BUILD SUCCESSFUL
Total time: 4 seconds

这说明,本身默认的docbook-xsl-ns-1.77.0中,对于xinclude就是支持的不好,或者说没有经过完整的验证,所以默认是把xinclude干掉了。。。

8. 然后试试之前的方法,build.xml中加上xercesImpl.jar,变成:

style="E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/profiling/profile.xsl" classpath="${xercesImpl.jar}">

然后试试,结果可以正常编译的:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/webhelp
$ ant webhelp -Doutput-dir=test-output
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\docsrc\readme.xml to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null84149495
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null84149495 to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\null1049188237
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing test-output/content/ch01.html for chapter
     [xslt] Writing test-output/content/ch02s01.html for section
     [xslt] Writing test-output/content/ch02s02.html for section
     [xslt] Writing test-output/content/ch02s03.html for section
     [xslt] Writing test-output/content/ch02s04.html for section
     [xslt] Writing test-output/content/ch02s05.html for section
     [xslt] Writing test-output/content/ch02.html for chapter
     [xslt] Writing test-output/content/ch03s01.html for section
     [xslt] Writing test-output/content/ch03s02.html for section
     [xslt] Writing test-output/content/ch03.html for chapter
     [xslt] Writing test-output/content/ch04.html for chapter
     [xslt] Writing test-output/content/ch05s01.html for section
     [xslt] Writing test-output/content/ch05s02.html for section
     [xslt] Writing test-output/content/ch05.html for chapter
     [xslt] Writing test-output/content/index.html for book
     [xslt] Writing test-output/index.html
     [xslt] Writing test-output/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [copy] Copying 2 files to E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\test-output
     [echo] Indexing html files in test-output/content
     [java] Stemming disabled
     [java] The created index files are located in test-output\content\search\.js
     [java] Delay = 685 milliseconds

webhelp:

BUILD SUCCESSFUL
Total time: 27 seconds

可见,其中xinclude进来的内容,变成了第五章了,并且去查看了下生成的webhelp,内容也是正常的。

不过提示一下,其中显示有点异常,本来xinclude-test.xml中的内容:

arsenal, arsenic, buys, says, varies, tries, skies, nuclei, days, keys, currencies, build.xml

被顶端部分遮住了,没显示出来,但是实际的html中是有的,说明生成的webhelp是正常的。

9.那么,就再去折腾自己的book,看看到底错在哪了。

目前所看到的区别是:

(1)xinclude-test.xml中的内容是:

<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  <chapter>
    xxx  
  </chapter>

其中顶端加了对应的DOCTYPE声明

(2)主文件中readme.xml是这样include子文件的:

<book xmlns="http://docbook.org/ns/docbook" version="5.0">
  <info>xxx</info>
  <chapter>xxx</chapter>
  <xi:include href="xinclude-test.xml"  xmlns:xi="http://www.w3.org/2001/XInclude"/>
</book>

看起来,是xi:include时,加了xmlns:xi,按理来说,应该和我顶部book中添加xmlns:xi没啥区别。但是还是要去改自己的book,和其用法一样,看看是否可以成功编译。

10.对照区别,去修改:

(1)给原先主文件arm_vs_mips.xml中xi:include的地方添加xmlns:xi,变成:

<xi:include href="glossary.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="ch01_reduced_instruction_set.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
<xi:include href="reference.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />

试试编译的结果如何。

结果还是和之前就遇到的错误一样:

[xslt] : Error! Error attempting to parse XML file (href=’ch01_reduced_instruction_set.xml’).

但是突然注意到,为何第一个glossary.xml始终都没有报错呢?

看来,此处xi:include的机制,应该是好的,可以识别glossary.xml,但只是没有识别ch01_reduced_instruction_set.xml而已,所以再去找具体原因。

11.看了下出错的xml中的内容是:

<?xml version='1.0' encoding="utf-8"?>

<!DOCTYPE chapter
[


]>

<chapter
    xmlns="http://docbook.org/ns/docbook"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xl="http://www.w3.org/1999/xlink"

    xml:id="ch01_reduced_instruction_set">
<title>在精简指令集以减小代码空间占用方面的对比</title>
<abstract></abstract>

<sect1>xxx</sect1>
</chapter>

然后网上搜了下:

ant webhelp Error attempting to parse XML file href=

找到:XML with Schema and XInclude in Java ,其自己通过“turned off Schema Validation ”解决了问题,但是偶还是看不太懂。

其第二篇:Usefull Errormessages With Schema and XInclude 中的解释,都是用的代码实现的,不太清楚这部分的逻辑,如何应用到此处的我当前的配置中。

12.用了最新的xercesImpl.jar和xml-apis.jar也还是同样错误。

13.暂时先把此出错的xml注释掉:

<!– <xi:include href="ch01_reduced_instruction_set.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/> –>

然后看看编译结果。

然后的确是可以编译通过的:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src
$ ant webhelp
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1549248938
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1549248938 to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1959603709
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing ../output/webhelp/content/glossary.html for glossary(glossary)
     [xslt] Writing ../output/webhelp/content/reference.html for bibliography(reference)
     [xslt] Writing ../output/webhelp/content/index.html for book
     [xslt] Writing ../output/webhelp/index.html
     [xslt] Writing ../output/webhelp/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copying 2 files to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [echo] Indexing html files in ../output/webhelp/content
     [java] Stemming disabled
     [java] The created index files are located in ..\output\webhelp\content\search\.js
     [java] Delay = 263 milliseconds

webhelp:

BUILD SUCCESSFUL
Total time: 4 seconds

然后再去看看那个文件ch01_reduced_instruction_set.xml到底哪部分内容,无法被xinclude所识别。

14.后来找到:

Saxon XSLT and XQuery Processor

但是里面的解决办法是将太旧的 1.5的java升级到1.6,而我这里java 本来就是最新的1.7所以对我没用。

不过其也提示到了,可以通过XInclude Engine解决问题,但是我去看了下,没太看懂怎么用。。。

15.找到:

Xinclude problem with docbook document

其解决问题了。但是没完全看懂。

不过导致也看到其提到:

http://xincluder.sourceforge.net/

http://people.freebsd.org/~znerd/xinclude-task/

然后就去第二个地址中看了下,其有介绍如何把xinclude加入到ant中的。

也看到解释了,此Ant XInclude task是基于前面那个the XIncluder project的。

然后按照教程去做:

(1)下载了xinclude-task-0.2.jar,放到E:\dev_install_root\apache_ant\apache-ant-1.8.4\lib中

(2)把:

<taskdef name="xinclude" classname="org.znerd.xincludetask.XIncludeTask" />

加入到E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml中。

然后又在<target name="chunk" depends="clean">中

<xslt

in="${input-xml}"

out="${xincluded-profiled.xml}"

style="E:/Dev_Root/docbook/tools/docbook-xsl-ns-1.77.0/profiling/profile.xsl" classpath="${xercesImpl.jar}">

之前,添加了

<xinclude in="${input-xml}" out="${xincluded-profiled.xml}" />

然后再去试试,结果出现错误:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src
$ ant webhelp --execdebug
exec "/cygdrive/d/Program Files/Java/jre7/bin/java" -classpath "E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib/ant-launcher.jar" -Dant.home="E:/dev_install_root/apache_ant/apache-ant-1.8.4" -Dant.library.dir="E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib" -Dcygwin.user.home="E:/dev_install_root/cygwin/home/Administrator" org.apache.tools.ant.launch.Launcher -cp ".;D:/Program Files/Java/jre7/lib" "webhelp"
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp

BUILD FAILED
E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml:36: java.lang.NoClassDefFoundError: com/elharo/xml/xinclude/XIncludeFilter
        at org.znerd.xincludetask.XIncludeTask.execute(XIncludeTask.java:131)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:392)
        at org.apache.tools.ant.Target.performTasks(Target.java:413)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:811)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: com.elharo.xml.xinclude.XIncludeFilter
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 17 more

Total time: 0 seconds

所以,还是不行。

16.还是去一点点注释掉ch01_reduced_instruction_set.xml的内容,看看是否能否定位到具体出错的代码,还是本身整个文件就无法正常xinclude,结果没有定位出来。

17.在ch01_reduced_instruction_set.xml中添加了:

<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">

结果运行结果是等了很长时间才出错的:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src
$ ant webhelp --execdebug
exec "/cygdrive/d/Program Files/Java/jre7/bin/java" -classpath "E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib/ant-launcher.jar" -Dant.home="E:/dev_install_root/apache_ant/apache-ant-1.8.4" -Dant.library.dir="E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib" -Dcygwin.user.home="E:/dev_install_root/cygwin/home/Administrator" org.apache.tools.ant.launch.Launcher -cp ".;D:/Program Files/Java/jre7/lib" "webhelp"
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1838473365
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] : Error! Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] Failed to process E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml

BUILD FAILED
E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml:41: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:195)

xxx
xxx
xxx
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 26 seconds

所以还是无法解决.

18.折腾到现在,仍是无法解决ant编译webhelp时的xinclude问题。

感觉还是saxon+ant对于xinclude支持的不够好啊。

还是xsltproc好,原来的docbook的xml源码,都很容易直接编译通过从来木有出现这么多的问题。

即使出现了,也是很快就能解决掉的。

19.再去对于build.xml中,使用Xerces去解析,即改为:

	 <!--TagSoup SAX Parser for parsing even the bad html contents. see 
	      http://sourceforge.net/tracker/?func=detail&aid=3401185&group_id=21935&atid=373750-->
         <!-- <sysproperty key="org.xml.sax.driver" value="org.ccil.cowan.tagsoup.Parser"/>
         <sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl"/> -->

         <!-- Uncomment the following if Xerces is your preference as the SAX XML Parser. Note that the indexing will fail with Xerces
	      if the html files are not XML-conformance -->
        <sysproperty key="org.xml.sax.driver"                   value="org.apache.xerces.parsers.SAXParser"/>
        <sysproperty key="javax.xml.parsers.SAXParserFactory"   value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
        <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration" value="org.apache.xerces.parsers.XIncludeParserConfiguration" />

然后看看结果错误有没有变化。结果错误依旧。

再切换回去。

20.再回去重新看看ch01_reduced_instruction_set.xml中哪些内容影响了xinclude无法正常执行。

(1)只保留chapter声明,全部留空 -> 可以正常编译

(2)只保留chapter和title -> 可以正常编译:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/arm_vs_mips/src
$ ant webhelp --execdebug
exec "/cygdrive/d/Program Files/Java/jre7/bin/java" -classpath "E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib/ant-launcher.jar" -Dant.home="E:/dev_install_root/apache_ant/apache-ant-1.8.4" -Dant.library.dir="E:/dev_install_root/apache_ant/apache-ant-1.8.4/lib" -Dcygwin.user.home="E:/dev_install_root/cygwin/home/Administrator" org.apache.tools.ant.launch.Launcher -cp ".;D:/Program Files/Java/jre7/lib" "webhelp"
Unable to locate tools.jar. Expected to find it in D:\Program Files\Java\jre7\lib\tools.jar
Buildfile: E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\build.xml

validate:

clean:
   [delete] Deleting directory E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null988865155
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] Processing E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null988865155 to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\null1167880178
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\xsl\webhelp.xsl
     [xslt] language: zh
     [xslt] Writing ../output/webhelp/content/glossary.html for glossary(glossary)
     [xslt] Writing ../output/webhelp/content/ch01_reduced_instruction_set.html for chapter(ch01_reduced_instruction_set)
     [xslt] Writing ../output/webhelp/content/reference.html for bibliography(reference)
     [xslt] Writing ../output/webhelp/content/index.html for book
     [xslt] Writing ../output/webhelp/index.html
     [xslt] Writing ../output/webhelp/content/search/l10n.js
     [copy] Copying 92 files to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp\content

index:
     [copy] Copying 1 file to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copied 1 empty directory to 1 empty directory under E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [copy] Copying 2 files to E:\Dev_Root\docbook\dev\books\arm_vs_mips\output\webhelp
     [echo] Indexing html files in ../output/webhelp/content
     [java] Stemming disabled
     [java] The created index files are located in ..\output\webhelp\content\search\.js
     [java] Delay = 256 milliseconds

webhelp:

BUILD SUCCESSFUL
Total time: 4 seconds

(3)最后经过调试,得到如下结果:

其实主要就是两处不同,导致之前的所有的编译错误:

A。

null的部分:

<!DOCTYPE chapter
[

<!ENTITY % crl_ent PUBLIC "crl.ent" 'null'>%crl_ent;

]>

导致了找不到文件的那个错误:

    [xslt] : Error! E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\null (系统找不到指定的文件。)
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\null (系统找不到指定的文件。)

B。而docbook中的xml的源码中,包含了entity,即&xxx;的字符,此处为"&TRADE;"对应着商标的那个特殊字符"",而此处由于已经删除了上述的ENTITY定义,那肯定是找不到的,结果就导致上述的错误:

     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\profiling\profile.xsl
     [xslt] : Error! Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
     [xslt] Failed to process E:\Dev_Root\docbook\dev\books\arm_vs_mips\src\arm_vs_mips.xml

BUILD FAILED
E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.0\webhelp\build.xml:41: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
        at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:195)
        at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:853)
        at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:389)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:392)
        at org.apache.tools.ant.Target.performTasks(Target.java:413)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:811)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href='ch01_reduced_instruction_set.xml').
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(Unknown Source)
        ... 22 more

此处,之所以又贴出一遍相关的错误信息,是由于想要在找出错误的根本原因后,反过来,看看是否能从原始错误信息中,按照道理来说,是否能否推断出此类错误的。

结果是从最底层的一些错误信息,还是看不出来是由于entity的问题而导致的:

com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file

的错误,所以,至少此处不能怪之前的一系列迷茫的问题调试过程了,因为的确是看不出来是这样的原因所导致的。

21.找到了问题根本原因了,那么剩下的就是去搞清楚如何把之前对于ENTITY的定义:

<!ENTITY % crl_ent PUBLIC "crl.ent" ‘null’>%crl_ent;

改写成什么样子,才可以使得之前的xsltproc和现在的ant均能正确识别。

22.接下来就是去研究ENTITY的语法了。

后来折腾出了正确的ENTITY的写法,参见这里:

【已解决】docbook中用ant编译webhelp时出错:[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: xxx\null (系统找不到指定的文件。)

 

 

【总结】

docbook中,用ant编译webhelp出现:

[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href=’xxx.xml’).

的错误的原因是:

xml文件中包含了(未解析的)实体定义:

"&TRADE;"(其对应着商标的那个特殊字符"")

导致ant编译webhelp过程中的xslt无法识别,最终显示出我们所看到的此错误。

而对于为何此处的"&TRADE;"没有定义,是由于之前为了尽快让ant可以继续编译,而删掉了之前错误的ENTITY的写法,所以导致此处没了定义。

解决办法是,把ENTITY定义添加回来。

此处我的是添加回来并且改为正确的写法详情参考:

【已解决】docbook中用ant编译webhelp时出错:[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: xxx\null (系统找不到指定的文件。)

由此,便解决了Error attempting to parse XML file 的问题。

转载请注明:在路上 » 【已解决】docbook中用ant编译webhelp时出错:[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Error attempting to parse XML file (href=’xxx.xml’).

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.212 seconds, using 22.46MB memory