Chapter 13. Working with XML
This chapter covers:
In this chapter we’re going to take a partial break from the web site and do some low-level XML work. Many Java projects need some XML processing at build time. It may be the need to create configuration files on the fly, or it could be the desire to generate Java source files from XML. This is essentially what all web service stacks do when they create Java classes from the XML files that describe the remote SOAP service.
We’re going to explore XML processing in Ant. We’ll see how to use Ant to validate the Atom feed of events coming off our diary web application, and to generate Java source files from XML templates. We’ll also look at the basic ways that Ant can work with XML.
Ant can perform four main actions with XML data:
- Write some XML into a file
- Validate an XML document
- Read Ant properties from an XML file
- Transform XML content into other XML documents, HTML files, or plain text
This will give a taste of Ant’s abilities and show its limits too. It will demonstrate where a bit of XML can benefit a Java application at build time, and how Ant can help.