Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmltask confused about dtd

Tags:

ant

dtd

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?

like image 980
skiphoppy Avatar asked Sep 29 '09 13:09

skiphoppy


People also ask

Is DTD mandatory for XML?

XML does not require a DTD. When you are experimenting with XML, or when you are working with small XML files, creating DTDs may be a waste of time.

What is the purpose of DTD in XML?

The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference.

What is a doctype in XML?

A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document (for example, a webpage) with a document type definition (DTD) (for example, the formal definition of a particular version of HTML 2.0 - 4.0).


2 Answers

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:

<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>

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>.

like image 164
skaffman Avatar answered Oct 22 '22 05:10

skaffman


As an alternative, it looks like I can skip the whole validation by creating a blank file with the same name as the DVD file, and then deleting the file when I am done. Odds are I am going to go that route instead of using the catalog.

like image 29
skiphoppy Avatar answered Oct 22 '22 04:10

skiphoppy