9.3. Creating Ant Task DTDs
The Ant documentation is useful but at times hard to use if you're looking for the definitions of nested tasks and elements, because they're not listed at the top level. On the other hand, if you can read a DTD and want to know how any Ant task or element is defined, use the antstructure task. This task will create a DTD for all Ant tasks that Ant knows about, including optional tasks, with their attributes and nested elements. This task only has one attribute, output, which specifies the output file to hold the DTD.
Example 9-4 shows how to use this task, storing the DTD for all Ant tasks in project.dtd.
Example 9-4. Using the antstructure task (ch09/antstructure/build.xml)
<?xml version="1.0" ?> <project default="main"> <target name="main"> <antstructure output="project.dtd"/> </target> </project>
Here's part of the DTD, project.dtd, generated:
<!ELEMENT project (target | %tasks; | %types;)*> <!ATTLIST project name CDATA #IMPLIED default CDATA #IMPLIED basedir CDATA #IMPLIED> <!ELEMENT target (%tasks; | %types;)*> <!ATTLIST target id ID #IMPLIED name CDATA #REQUIRED if CDATA #IMPLIED unless CDATA #IMPLIED depends CDATA #IMPLIED description CDATA #IMPLIED> <!ELEMENT patternset (include | patternset | exclude | excludesfile | includesfile)*> <!ATTLIST patternset id ID #IMPLIED includes CDATA #IMPLIED refid IDREF #IMPLIED description CDATA #IMPLIED excludesfile CDATA #IMPLIED includesfile CDATA #IMPLIED excludes CDATA #IMPLIED> . . .