我正在尝试使用目录文件来覆盖XML文件中的DTD位置。我尝试了How to use saxon built-in catalog feature这里的所有提示,但无法让它发挥作用。我简化为这个简单的例子:
Saxon的确认版本:
C:\test>java net.sf.saxon.Query
No query file name
Saxon-HE 9.7.0.7J from Saxonica
...
我的目录文件。我试图减少到最简单(uriSuffix):
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uriSuffix uriSuffix="bad.dtd" uri="good.dtd" />
</catalog>
已确认的解析程序位于类路径中,其行为符合目录:
C:\test>java org.apache.xml.resolver.apps.resolver -c didcat.xml -u bad.dtd uri
Cannot find CatalogManager.properties
Resolve URI (uri):
uri: bad.dtd
Result: file:/C:/test/good.dtd
简单的test.xml文件:
<?xml version="1.0"?>
<!DOCTYPE a SYSTEM "bad.dtd">
<a>hello world</a>
简单的test.xql:
doc("test.xml")/a
结果:
C:\test>java net.sf.saxon.Query -t -catalog:didcat.xml test.xql
Loading catalog: didcat.xml
Saxon-HE 9.7.0.7J from Saxonica
Java version 1.8.0_101
Analyzing query from test.xql
Analysis time: 131.650519 milliseconds
Resolved URI: test.xml
file:/C:/test/test.xml
Building tree for file:/C:/test/test.xml using class net.sf.saxon.tree.tiny.TinyBuilder
Error on line 2 column 6 of test.xql:
FODC0002: I/O error reported by XML parser processing file:/C:/test/test.xml:
C:\test\bad.dtd (The system cannot find the file specified)
Query failed with dynamic error: I/O error reported by XML parser processing file:/C:/test/test.xml: C:\test\bad.dtd (The system cannot find the file specified)
我尝试了一些不同的目录技术来覆盖DTD URI但没有一个成功。我究竟做错了什么?提前致谢。
答案 0 :(得分:1)
要解析对DTD等XML实体的引用,您需要使用目录中的systemSuffix
条目,而不是uriSuffix
条目。将目录更改为
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<systemSuffix systemSuffix="bad.dtd" uri="good.dtd" />
</catalog>