XML validation with Ant



Hi

I have the following small test project:

build.xml:
<?xml version="1.0"?>

<project default="valid">
<target name="valid">
<xmlvalidate file="date.xml"/>
</target>
</project>

date.dtd:
<!ELEMENT date (#PCDATA)>

date.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE date SYSTEM "date.dtd">
<date>2003-01-31T00:00:01</date>


And it works fine:
robert-desktop:~/code $ ant
Buildfile: build.xml

valid:
[xmlvalidate] 1 file(s) have been successfully validated.

BUILD SUCCESSFUL
Total time: 0 seconds
robert-desktop:~/code $

The problem is that in my REAL project, the DTD is placed in a jar file
and thus cannot be referenced as easily. I believe that Ant can cope
with that by using 'resources' which can be the content of a
zip/jar/whatever file. But I cannot seem to get a very simple test working:

robert-desktop:~/code $ cat build.xml
<?xml version="1.0"?>

<project default="valid">
<target name="valid">
<xmlvalidate file="date.xml">
<dtd publicId="//KOV/Test//EN" location="date.dtd"/>
</xmlvalidate>
</target>
</project>
robert-desktop:~/code $ cat date.xml
<?xml version="1.0" encoding="UTF-8"?>

<date>2003-01-31T00:00:01</date>
robert-desktop:~/code $ cat date.dtd
<!ELEMENT date (#PCDATA)>
robert-desktop:~/code $ ant
Buildfile: build.xml

valid:
[xmlvalidate] /var/code/date.xml:3:7: Document root element "date", must
match DOCTYPE root "null".
[xmlvalidate] /var/code/date.xml:3:7: Document is invalid: no grammar found.

BUILD FAILED
/var/code/build.xml:5: /var/code/date.xml is not a valid XML document.

Total time: 0 seconds
robert-desktop:~/code $

Here I use the <dtd> tag to specify the location of the DTD that the XML
file should be validated against.
I have also tried to specify the full path for the DTD:
<dtd publicId="//KOV/Test//EN" location="/home/robert/code/date.dtd"/>

....but with the same result. Do any of you know what I am doing wrong ?

Best,
Robert
.



Relevant Pages

  • Re: Apache Ant and XSLT and loading DTD
    ... this ant will download the DTD of the input xml file. ... Because I am behing a proxy I need to specify one for ant as well, ... Were it actual emergency, you wouldn't be able to read this. ...
    (comp.lang.java.programmer)
  • Re: Apache Ant and XSLT and loading DTD
    ... this ant will download the DTD of the input xml file. ... Because I am behing a proxy I need to specify one for ant as well, ... likely be China and America," concludes the report. ...
    (comp.lang.java.programmer)
  • Re: Apache Ant and XSLT and loading DTD
    ... this ant will download the DTD of the input xml file. ... Because I am behing a proxy I need to specify one for ant as well, ... "I have made good judgments in the past. ...
    (comp.lang.java.programmer)
  • Re: Apache Ant and XSLT and loading DTD
    ... this ant will download the DTD of the input xml file. ... Because I am behing a proxy I need to specify one for ant as well, ... Garbage out' springs to mind. ...
    (comp.lang.java.programmer)
  • ANT config - running java
    ... I get this error when trying to run a java ... jonathan@linux:~/work> ant run ... Buildfile: build.xml ... Jon ...
    (comp.lang.java.help)