【问题标题】:Should an XML catalog be able to resolve modules?XML 目录应该能够解析模块吗?
【发布时间】:2020-09-28 19:03:24
【问题描述】:

我正在尝试使用这样的文档类型在 XML 上运行 XSL 转换:

<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d3 20150301//EN" "http://jats.nlm.nih.gov/publishing/1.1d3/JATS-journalpublishing1.dtd">

我在处理器周围使用 Java 11:

Source s = getXsl(src, bibSources);

System.setProperty("javax.xml.accessExternalDTD", "all");
System.setProperty("javax.xml.accessExternalSchema", "all");
System.setProperty("javax.xml.catalog.files", xmlCatalog);

System.setProperty(CatalogFeatures.Feature.RESOLVE.getPropertyName(), "strict");

TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
factory.setFeature("http://saxon.sf.net/feature/suppressXsltNamespaceCheck",true);
StringWriter writer = new StringWriter();
StreamResult streamResult = new StreamResult(writer);

Transformer t = factory.newTransformer(s);
Source xml = new StreamSource(zip.getInputStream(entry));
t.transform(xml,streamResult);

我在运行转换时遇到的错误是这样的:

Error on line 333 column 31 of JATS-journalpublishing1.dtd:
  SXXP0003: Error reported by XML parser: JAXP00090001: The CatalogResolver is enabled with
  the catalog "catalog.xml", but a CatalogException is returned.: JAXP09040001: No match
  found for publicId '-//NLM//DTD JATS (Z39.96) Journal Publishing DTD-Specific Modules
  v1.1d3 20150301//EN' and systemId 'JATS-journalpubcustom-modules1.ent'.

正在访问目录,但似乎无法解析 DTD 所依赖的模块。这是正常的,还是我在 Java 中错误地设置了 XML 属性?

编辑:

XML 目录有一个 dtd 条目:

<public publicId="-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.1d3 20150301//EN" uri="http://ecswebqa02:8080/xml-catalog/dtd/jatsDTD/JATS-Publishing-1-1d3-MathML2-DTD/JATS-journalpublishing1.dtd"/>

目录没有模块的条目,尽管模块位于 dtd 的本地副本附近:

http://ecswebqa02:8080/xml-catalog/dtd/jatsDTD/JATS-Publishing-1-1d3-MathML2-DTD/JATS-journalpubcustom-modules1.ent

【问题讨论】:

  • 那么catalog.xml看起来怎么样?
  • 错误消息不是报告定位 DTD 的问题,而是报告外部实体引用的问题。
  • @MichaelKay 这是目录的问题,而不是我在 Java 中的设置,对吧?我每天可能会运行数以万计的 XML 文件,因此我无法继续访问公共 URL。如果问题出在这个目录上,是否每个实体都需要在目录中拥有自己的条目,以及引用它们的 DTD?
  • 我应该提到该目录归另一个团队所有。我不能轻易改变它。
  • @MartinHonnen 目录用了几年了,不熟悉。如果 RESOLVE 的 Java 属性设置为“忽略”或“继续”,这些实体是否只是未解析,还是已从网络中删除?

标签: xml xslt-2.0 java-11 saxon dtd


【解决方案1】:

如果实体的相对 URI 正确,我希望解析器做正确的事情。如果您使用的是 Apache 公共解析器,则可以通过打开“xml.catalog.verbosity”设置来获得更详细的处理消息,http://xerces.apache.org/xml-commons/components/resolver/resolver-article.html

您也可以尝试更新的https://xmlresolver.org/ 解析器。

【讨论】:

  • 在我的例子中,我没有在我的转换器中设置一个显式的 xml 解析器。我假设我设置的系统属性由 Saxon 拥有的任何默认解析器使用。如果我将 RESOLVE 属性设置为“继续”或“忽略”而不是“严格”,则此方法有效。如果我不使用“严格”,究竟会发生什么?丢失的文件是从网上下载的吗?他们只是不被使用吗?我不确定这怎么可能。很困惑。
猜你喜欢
  • 2014-06-02
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多