xmltask 对 dtd 感到困惑 [英] xmltask confused about dtd

查看:29
本文介绍了xmltask 对 dtd 感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 xmltask for ant 来修改子目录中的文件:

I'm trying to use xmltask for ant to modify a file in a subdirectory:

project/path/to/file.xml

该文件引用了这样的 DTD:

The file refers to a DTD like this:

<!DOCTYPE data SYSTEM "mydtd.dtd">

我无法灵活更改这些文档.

I don't have the flexibility to change these documents.

这个 DTD 存储在同一个子目录中,它一直工作正常:

This DTD is stored in the same subdirectory, which has always worked fine:

project/path/to/mydtd.dtd

不幸的是,xmltask 试图在我的项目的顶级目录中定位 dtd,这是我的构建文件所在的位置,也是我运行的位置:

Unfortunately, xmltask is trying to locate the dtd in my project's top-level directory, which is where my build file is located, and where I run from:

[xmltask] java.io.FileNotFoundException:/home/me/project/mydtd.dtd(系统找不到指定的文件)

[xmltask] java.io.FileNotFoundException: /home/me/project/mydtd.dtd (The system cannot find the file specified)

我在 xmltask 文档中看到,我可以使用 xmlcatalog 元素来纠正这个问题,告诉它在哪里查找文件.但是我需要使用一个dtd元素,而且我只能找到这个元素的例子,没有文档;这些示例仅显示了一个 publicId,如果我正确理解 XML,则该文档没有一个.无论如何,我不需要指定这个,对吧,因为我的文档已经说我的 DTD 存储在本地并显示它在哪里?

I see in the xmltask documentation that I can correct this with an xmlcatalog element to tell it where to look up the file. But I need to use a dtd element, and I can only find examples for this element, not documentation; the examples show only a publicId, and if I understand XML correctly this document does not have one. I shouldn't need to specify this, anyway, right, since my document already says my DTD is stored locally and shows right where it is?

为什么 xmltask 不能正确查找 DTD?纠正或解决这种情况的最佳方法是什么?

Why isn't xmltask finding the DTD correctly? What's the best way to correct or work around this situation?

推荐答案

XML Catalog 是解决问题的方法,只是需要多一点坚持.

An XML Catalog is the way to go here, it just needs a bit more perseverance.

正如您正确指出的那样,标准 Ant 类型仅允许您在使用内联语法时指定公共 DTD 引用,这对您没有用.但是, 还允许您指定标准的 OASIS 语法目录,该目录更加丰富,包括解析 SYSTEM DTD 引用.

As you correctly pointed out, the standard Ant <XmlCatalog> type only allows you to specify public DTD references when using the inline syntax, which is of no use to you. However, <XmlCatalog> also lets you specify a standard OASIS-syntax catalog, which is far richer, including resolving SYSTEM DTD references.

OASIS 目录(完整规范此处) 看起来像这样:

An OASIS catalog (full spec here) looks like this:

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">      
  <system systemId="mydtd.dtd" uri="project/path/to/mydtd.dtd"/>
</catalog>

然后您可以从 中引用此目录:

You can then reference this catalog from the <XmlCatalog>:

<xmlcatalog refid="commonDTDs"/>
  <catalogpath>
    <pathelement location="path/to/oasis.catalog"/>
  </catalogpath>
</xmlcatalog>

就是这样.最好建立一个可重用的 OASIS 目录文件,并从各种与 XML 相关的 Ant 任务中引用它,所有这些都可以使用 .

And that's that. It's a good idea to build up a reusable OASIS catalog file, and refer to it from various XML-related Ant tasks, all of which can use <XmlCatalog>.

这篇关于xmltask 对 dtd 感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆