Chapter 9. XML and XDoclet

XML support is built into Ant, and not only as far as build files go. You can validate XML documents using XML DTDs and schemas using the xmlvalidate task. You can read properties from an XML document using xmlproperty. You can use the xslt/style task to transform XML documents using XSLT. And you can use the antstructure task to generate an XML DTD for all the tasks Ant knows about.

Besides covering these and other XML tasks, I'm going to discuss XDoclet in this chapter. XDoclet is an open source code generation engine that is designed to run in Ant. Using codes that you embed in Java source code, XDoclet can generate code, deployment descriptors such as web.xml, and other artifacts for Web and EJB applications.

I'll also round out the discussion of EJB from the previous chapter by discussing the Ant EJB tasks, a specially designed set of optional tasks for developing Enterprise JavaBeans (EJBs).

Validating XML Documents

You use the xmlvalidate task to validate XML documents with Document Type Definitions (DTDs) or XML schema. Your build process may involve generating XML documents, and it can be worthwhile to test those documents for validity before deploying them (for example, see the section on XDoclet in this chapter. You typically use XDoclet to generate XML documents for deploying web applications, such as web.xml, application.xml, and so on). By default, this task uses the SAX2 parser implementation provided by Sun's JAXP (http://java.sun.com/xml/jaxp/index.jsp ...

Get Ant: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.