Is there a DTD that I can use to validate my build files?php
An incomplete DTD can be created by the <antstructure>
task - but this one has a few problems:html
<taskdef>
it won't know about it. See this page by Michel Casabianca for a solution to this problem. Note that the DTD you can download at this page is based on Ant 0.3.1. <test>
and <junit>
tasks, there are two XML elements named test
(the task and the nested child element of <junit>
) with different attribute lists. This problem cannot be solved; DTDs don't give a syntax rich enough to support this.
雖然dtd會限制ant的可擴展性可是在語法提示的誘惑下仍是生成了這個DTD;apache
方法大體以下:app
1.創建一個build.xmlui
2.輸入內容:this
<?xml version="1.0" encoding="UTF-8"?>
<project>
<target name="makedtd">
<antstructure output="project.dtd" />
</target>
</project>spa
3.到build.xml所在目錄下執行ant_home%/bin/ant makedtdcode
4.BUILD FAILED!發生一個NoClassDefFoundError錯誤,大體是說org/apache/commons/net/ftp/FTPClientConfig沒找到orm
可是project.dtd仍是生成了,我這裏這個ANT1.7生成的115KB。xml
5.爲了解決這個問題首先查得FTPClientConfig是apache的commons-net包的,因而下載http://apache.mirror.phpchina.com/commons/net/binaries/commons-net-1.4.1.zip,放到ant_home的lib目錄下 ,再次構建 OK ,沒有錯誤提示project.dtd生成202KB。
不過好像給XMLSpy掛上仍是沒有語法提示 -_-
6.仔細看了一下原來生成的DTD裏邊有幾處問題。
1)第六行<!ELEMENT project (target | %tasks; | %types;)*>
此行末尾的‘*’號應該爲‘+’號由於每一個build.xml都應該起碼有一個<project>元素
2)根據XMLSpy提示,有個定義<!ELEMENT targe EMPTY>。
3) 根據XMLSpy提示<!ELEMENT FTP.........>這塊也有問題,因爲平時基本不會用到所以刪掉。
OK 如今已是個良好格式(well-formet)的project.dtd文件了。
如今經過XMLSpy根據此project.dtd 創建的build.xml就具有了通常的語法提示功能了。