I mentioned DTD validation of generated XML a few posts ago. I've
implemented it (wasn't hard at all), and it works fine.
As soon as I get commit access (thanks, Ara!) , I'll add it if nobody
is against it. Changes are more or less:
-New class xdoclet.ValidatorHandler extends
org.xml.sax.helpers.DefaultHandler
-Added a protected void validateXML( String xmlFileName,
ValidatorHandler validatorHandler ) throws BuildException in
xdoclet.SubTask that can be called from subclasses.
-Modified my WeblogicSubTask and EjbDotXmlSubTask to verify that it
works.
-Added a new setValidatexml( boolean flag ) method to SubTask, so
validation can be turned on/off from Ant.
Then it's only a matter of adding a few lines of code to each task to
enable xml validation. Example of addition in EjbDotXmlSubTask:
diff -r1.7 EjbDotXmlSubTask.java
29a30,35
> protected static String DD_20_PUBLICID = "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 2.0//EN";
> protected static String DTD_20_FILE_NAME = "ejb20-jar.dtd";
> protected static String DD_11_PUBLICID = "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 1.1//EN";
> protected static String DTD_11_FILE_NAME = "ejb11-jar.dtd";
>
> private final static ValidatorHandler _ejbJarHandler = new
ValidatorHandler( EjbDotXmlSubTask.class );
108a115,122
> if( validateXML )
> {
> validateXML( DD_FILE_NAME, _ejbJarHandler );
> }
> }
> static
> {
> _ejbJarHandler.registerDTD( DD_20_PUBLICID,
DTD_20_FILE_NAME );
(I guess you guys read diff output as easily as anything else :)
Further, the dtd files must reside along with the .j files. This is to
avoid loading the DTDs over the net when validation occurs.
Typical error message if generated XML is bad is: (I introduced a typo
in ejb-jar_xml.j to provoke an error):
[ejbdoclet] Generated file
[file:D:/bootcamp/pervers/j2eeproject/build/ejb/META-INF/ejb-
jar.xml:line 9] is not valid according to its DTD: Element "ejb-jar"
does not allow "QQenterprise-beans" here.
:Aslak.
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel