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

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

问题描述

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

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目录是这里的解决之道,它只需要更多的毅力.

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

正如您正确指出的那样,标准Ant <XmlCatalog>类型仅允许您在使用内联语法时指定公共DTD引用,这对您没有用.但是,<XmlCatalog>还允许您指定标准的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>

然后您可以从<XmlCatalog>引用此目录:

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

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

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

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天全站免登陆