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

【未解决】Docbook中,让ant支持外部catalog文件,以支持systemId的entity

Docbook crifan 2146浏览 0评论

【背景】

之前已经解决了让docbook中的ant支持内置catalog:

【已解决】给Docbook的基于saxon的ant webhelp中添加catalog支持

后来是由于之前的了解:

【整理】XML Catalog,PUBLIC和SYSTEM的ENTITY

所以想要去把publicId改为更简单的systemId。

 

【解决过程】

1. 所以就去把E:\Dev_Root\docbook\dev\ant\webhelp\build.xml中的配置改为:

    <xmlcatalog id="crl_catalog">
        <dtd 
            systemId="crl.ent"
            location="file:///E:/Dev_Root/docbook/dev/config/entity/crl.ent"/>
    </xmlcatalog>

然后对应的xml中使用:

<!ENTITY % crl_ent SYSTEM "crl.ent">%crl_ent;

然后去编译,结果出现了所预料的错误。

2. 具体错误信息为:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/rec_soft_npp/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\rec_soft_npp\src\build.xml

BUILD FAILED
E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\build.xml:3: The following error occurred while executing this line:
E:\Dev_Root\docbook\dev\ant\webhelp\build.xml:29: dtd doesn't support the "systemId" attribute

Total time: 0 seconds

说是dtd doesn’t support the "systemId" attribute,这和之前所看到的XMLCatalog中的提示:

Currently, only <dtd> and <entity> elements may be specified inline; these roughly correspond to OASIS catalog entry types PUBLIC and URI respectively.

另外,此处刚刚看到,因为上面是属于internal的catalog支持,所以是:

dtd对应着PUBLIC;

entity对应着URI;

而如果是引用外部的catalog文件的话,则是对应着后面那句所说的:

By contrast, external catalog files may use any of the entry types defined in the +OASIS specification.

即,应该就可以使用systemId了。

3.而如何使用external的catalog,还要继续折腾才行。

又看到上面帖子中提到了:

In addition, external catalog files may be specified in a nested catalogpath , but they will be ignored unless the resolver library from xml-commons is available in the system classpath. Due to backwards incompatible changes in the resolver code after the release of resolver 1.0, Ant will not support resolver.jar in version 1.0 – we expect a resolver release 1.1 to happen before Ant 1.6 gets released. A separate classpath for entity resolution may be specified inline via nested classpath elements; otherwise the system classpath is used for this as well.

所以,继续去尝试把代码改为:

  <!--
    <xmlcatalog id="crl_catalog">
        <dtd 
            systemId="crl.ent"
            location="file:///E:/Dev_Root/docbook/dev/config/entity/crl.ent"/>
            
            E:\Dev_Root\docbook\dev\config\catalog\catalog.xml
    </xmlcatalog>
  -->
  
        <xmlcatalog refid="crl_catalog">
            <catalogpath>

                <fileset 
                    dir="E:/Dev_Root/docbook/dev/config/catalog"
                    includes="**/catalog.xml"/>
            </catalogpath>
        </xmlcatalog>

结果运行出错:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/rec_soft_npp/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\rec_soft_npp\src\build.xml

BUILD FAILED
E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\build.xml:3: The following error occurred while executing this line:
E:\Dev_Root\docbook\dev\ant\webhelp\build.xml:39: You must not specify nested elements when using refid

Total time: 0 seconds

4. 然后又改为:

  <!--
    <xmlcatalog id="crl_catalog">
        <dtd 
            systemId="crl.ent"
            location="file:///E:/Dev_Root/docbook/dev/config/entity/crl.ent"/>
            
            E:\Dev_Root\docbook\dev\config\catalog\catalog.xml
    </xmlcatalog>
  -->
  
        <xmlcatalog id="crl_catalog">
            <catalogpath>

                <fileset 
                    dir="E:/Dev_Root/docbook/dev/config/catalog"
                    includes="**/catalog.xml"/>
            </catalogpath>
        </xmlcatalog>

结果出现其他错误:

Administrator@K470 /cygdrive/e/Dev_Root/docbook/dev/books/rec_soft_npp/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\rec_soft_npp\src\build.xml

validate:

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

chunk:
    [mkdir] Created dir: E:\Dev_Root\docbook\dev\books\rec_soft_npp\output\webhelp
     [xslt] Processing E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\rec_soft_npp.xml to E:\Dev_Root\docbook\dev\books\rec_soft_npp\output\webhelp\null2034106437
     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.1\profiling\profile.xsl
Warning: XML resolver not found; external catalogs will be ignored
     [xslt] : Error! E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)
     [xslt] Failed to process E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\rec_soft_npp.xml

BUILD FAILED
E:\Dev_Root\docbook\dev\ant\webhelp\build.xml:59: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)
        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: E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)

5. 看到是找不到我的那个ent文件,所以,再改为:

  <!--
    <xmlcatalog id="crl_catalog">
        <dtd 
            systemId="crl.ent"
            location="file:///E:/Dev_Root/docbook/dev/config/entity/crl.ent"/>
            
            E:\Dev_Root\docbook\dev\config\catalog\catalog.xml
    </xmlcatalog>
  -->
  
        <xmlcatalog id="crl_catalog">
            <catalogpath>

                <fileset 
                    dir="file:///E:/Dev_Root/docbook/dev/config/catalog"
                    includes="**/catalog.xml"/>
            </catalogpath>
        </xmlcatalog>

然后还是出错,所以再去找原因。

6。 但是看到:

[xslt] E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\file:\E:\Dev_Root\docbook\dev\config\catalog does not exist.

则很明显是两个地址叠加了,所以应该是base.dir之类没有指定的原因。

所以再去改为:

        <xmlcatalog id="crl_catalog">
            <catalogpath>
                <pathelement location="E:/Dev_Root/docbook/dev/"/>

                <fileset 
                    dir="/config/catalog"
                    includes="**/catalog.xml"/>
            </catalogpath>
        </xmlcatalog>

然后还是出错。

7. 最后经过折腾,发现改为:

        <xmlcatalog id="crl_catalog">
            <catalogpath>
                <fileset 
                    dir="E:/Dev_Root/docbook/dev/config/catalog"
                    includes="catalog.xml"/>
            </catalogpath>
        </xmlcatalog>

然后错误就变为了:

     [xslt] Loading stylesheet E:\Dev_Root\docbook\tools\docbook-xsl-ns-1.77.1\profiling\profile.xsl
Warning: XML resolver not found; external catalogs will be ignored
     [xslt] : Error! E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)
     [xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\crl.ent (系统找不到指定的文件。)
     [xslt] Failed to process E:\Dev_Root\docbook\dev\books\rec_soft_npp\src\rec_soft_npp.xml

即,变为找不到XML resolver了。

所以就再去找XML resolver。

8.后来再看了:

关于SAX,DOM,JAXP,JDOM,DOM4J的一些理解

之后,对相关知识有了进一步的了解后,

去:

Apache XML Commons Resolver -> The Apache Xerces™ Project – Downloads

下载了对应的

Xerces2 Java 2.11.0 – tar.gz

然后把解压得到的resolver.jar拷贝到ant的lib文件夹:

E:\dev_install_root\apache_ant\apache-ant-1.8.4\lib

之后,再运行,就没了那个

Warning: XML resolver not found; external catalogs will be ignored

的错误了。但是还是出现

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

的错误。

9.参考:Path-like Structures去改为:

        <xmlcatalog id="crl_catalog">
            <catalogpath>
              <pathelement path="E:/Dev_Root/docbook/dev/"/>
              <pathelement location="config/catalog/catalog.xml"/>

            </catalogpath>
        </xmlcatalog>

结果还是出错。

10.目前决定暂时不折腾了。因为剩下的主要工作就是去搞懂ant里面的catalogpath,pathelement,fileset等内容,使得可以正确制定对应的

E:/Dev_Root/docbook/dev/config/catalog/catalog.xml

即可。

有空再折腾。

转载请注明:在路上 » 【未解决】Docbook中,让ant支持外部catalog文件,以支持systemId的entity

发表我的评论
取消评论

表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.191 seconds, using 22.31MB memory