我试图使用一个目录文件来覆盖XML文件中的DTD位置。我尝试按照这里的所有提示使用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,但是都不成功。我做错了什么?提前感谢。
要解析对XML实体(如dtd)的引用,您需要使用目录中的< code>systemSuffix条目,而不是< code>uriSuffix条目。将您的目录更改为
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<systemSuffix systemSuffix="bad.dtd" uri="good.dtd" />
</catalog>