Pipeline XML with Ant
Ant is an extensible, open source build tool written in Java and sponsored by Apache. It can also be used as a framework for performing a large variety of operations--including XML-related tasks--in a single step.
Ant (http://ant.apache.org) uses build files that are written in XML, and takes advantage of XML in a variety of ways. It’s a suitable (if not ideal) framework for XML pipelining—it’s open, mature, stable, readily available, widely known and used, easily extensible, and already amenable to XML processing. What else could you ask for?
In this hack, I’ll show you the XML structures in an Ant build file, named build.xml by default; talk about some common XML-related tasks that Ant can perform; and end with an example of XML pipelining.
To get the examples in this hack to work, you’ll need to download and install Ant Version 1.6.1 (or later) binaries from http://ant.apache.org/bindownload.cgi. Because you’ll be using an external task that validates with RELAX NG (http://www.relaxng.org) schemas, you’ll also need James Clark’s Jing (http://www.thaiopensource.com/relaxng/jing.html).
Validating an XML Document
Ant
has a task for validating XML documents called
xmlvalidate
. By default, Ant validates with
Xerces. The XML document
valid.xml
is shown in Example 7-1.
Example 7-1. valid.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE time SYSTEM "time.dtd"> <!-- a time instant --> <time timezone="PST"> <hour>11</hour> <minute>59</minute> <second>59</second> ...
Get XML Hacks 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.