I’m trying to use xmltask for ant to modify a file in a subdirectory:
project/path/to/file.xml
The file refers to a DTD like this:
<!DOCTYPE data SYSTEM "mydtd.dtd">
I don’t have the flexibility to change these documents.
This DTD is stored in the same subdirectory, which has always worked fine:
project/path/to/mydtd.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 (The system cannot find the file specified)
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?
Why isn’t xmltask finding the DTD correctly? What’s the best way to correct or work around this situation?
An XML Catalog is the way to go here, it just needs a bit more perseverance.
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.An OASIS catalog (full spec here) looks like this:
You can then reference this catalog from the
<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>.