AntStructure

說明

為 Apache Ant 建置檔案產生一個 DTD,其中包含 Ant 目前已知的所有任務資訊。

實際上,DTD 並非建置檔案的真實 DTD,因為 Ant 使用 XML 的方式無法用 DTD 擷取。Ant 中的幾個元素可能有不同的屬性清單,視包含它們的元素而定。例如,<fail> 可以是任務,也可以是 <sound> 任務的巢狀子元素。請勿將產生的 DTD 視為依賴的對象。

另外請注意,此任務產生的 DTD 並不完整,您隨時可以使用 <taskdef><typedef> 新增 XML 實體。請參閱 此處,了解解決此問題的方法。

此任務不了解必要的屬性,所有屬性都將列為 #IMPLIED

自 Ant 1.7 起,可以使用自訂結構印表機,取代發射 DTD 的印表機。若要插入您自己的結構,您必須實作介面 org.apache.tools.ant.taskdefs.AntStructure.StructurePrinter,並 <typedef> 您的類別,然後將新類型用作此任務的巢狀元素—請參閱以下範例。

參數

屬性 說明 必要
輸出 要寫入 DTD 的檔案。

範例

基本用法

<antstructure output="project.dtd"/>

發射您自己的結構,而非 DTD:首先,您需要實作介面

package org.example;
import org.apache.tools.ant.taskdefs.AntStructure;
public class MyPrinter implements AntStructure.StructurePrinter {
    ...
}

然後透過 typedef 使用它

<typedef name="myprinter" classname="org.example.MyPrinter"/>
<antstructure output="project.my">
  <myprinter/>
</antstructure>

您自己的 StructurePrinter 可以接受屬性和巢狀元素,就像任何其他 Ant 類型或任務一樣。