XML validation with Ant
- From: Robert Larsen <robert@xxxxxxxxxxxx>
- Date: Tue, 29 Jan 2008 10:42:20 +0100
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
.
- Prev by Date: Re: Java Autopostback?
- Next by Date: How is Java typically invoked from HTML?
- Previous by thread: Java Autopostback?
- Next by thread: How is Java typically invoked from HTML?
- Index(es):
Relevant Pages
|
|