xmltask confused about dtd

血红的双手。 提交于 2019-12-04 10:04:07

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

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.

xmltask isn't finding it because it is looking in the current working directory. Ant allows you to specify a base directory using the basedir attribute of the <target> element. So I suggest you try this:

<target basedir="path/to" ...>
  <xmltask...
</target>

It strikes me that it is not the XML/DTD that you really have the problem with, but getting xmltask to interact with the two of them as you want.

If that fails, you could use the Ant Copy task to copy the XML and DTD to the root folder before processing with xmltask, then copying back again.

manji

Have you tried:

<!DOCTYPE data SYSTEM "./path/to/mydtd.dtd">

? Or an absolute path?

Also, you can find <dtd> description here.

I had a similar problem where an XML file had a doctype with SYSTEM reference that could not be changed.

<!DOCTYPE opencms SYSTEM "http://www.opencms.org/dtd/6.0/opencms-modules.dtd">

I first went down the road and created a catalog file with the OASIS catalog as described above, but to be able to use external catalogs I had to include the Apache Commons Resolver 1.1 (resolver.jar) in the Ant classpath (see http://ant.apache.org/manual/Types/xmlcatalog.html).

Because I had multiple machines on which this build was supposed to run this seemed overkill, especially since xmltask worked fine if I just removed the doctype definition. I wasn't allowed to remove it permanently because the doctype was needed elsewhere.

Ultimately I used this workaround: I commented out the doctype definition using Ant's replace task, ran the xmltask, and then put the doctype back into the file.

<replace file="myxmlfile.xml">
    <replacetoken>&lt;!DOCTYPE opencms SYSTEM "http://www.opencms.org/dtd/6.0/opencms-modules.dtd"&gt;</replacetoken>
    <replacevalue>&lt;!-- !DOCTYPE opencms SYSTEM "http://www.opencms.org/dtd/6.0/opencms-modules.dtd" --&gt;</replacevalue>
</replace>

<xmltask .../>

<replace file="${local.opencms.webapp.webinf}/config/opencms-modules.xml">
    <replacetoken>&lt;!-- !DOCTYPE opencms SYSTEM "http://www.opencms.org/dtd/6.0/opencms-modules.dtd" --&gt;</replacetoken>
    <replacevalue>&lt;!DOCTYPE opencms SYSTEM "http://www.opencms.org/dtd/6.0/opencms-modules.dtd"&gt;</replacevalue>
</replace>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!