Abbey Workshop | ||||||||||
I ran across an odd problem today. While trying to get Apache Ant 1.6.1 to perform schema validation on all the XML files in a directory, the following error is generated:
validate_project_files: [xmlvalidate] /user/dir/path/project1.prj.xml:6:2: cvc-elt.1: Cannot find the declaration of element 'project'.
Here is the Ant script that would not run:
Download source for: build_bad.xml
Using Ant to do mass XML schema validation seems pretty straightforward. You create a target that contains the xmlvalidate task, create a fileset like line 7, and turn on schema validation with lines 8 and 9. (XML Schema validation is not enabled by default in the Xerces parser, which is included with Ant.) That's it, it should work, right? Well it didn't. I tried everything I could. Changed the schema link from a relative to an absolute path. Tried with and without a namespace. No change.
So taking a look at some other examples, there seemed to be a couple more options that could be added to the xmlvalidate task. So to make a long story short, adding lines 6 and 7 to the file solved the problem.
Download source for: build.xml
Upon further review, line 6 seemed to be key. I'm guessing this is some sort of classpath problem (more than one Xerces.jar file in my classpath). However, I don't really have time to troubleshoot the problem thoroughly so that is it for now.
Copyright © Abbey Workshop 2006