SweetXML User Guide

Table of Contents

Ant Integration

SweetXML Ant Task

SweetXML provides an Ant task for copying and converting files between XML and SweetXML. This allows you convert any XML file which is bundled into you app at build time to SweetXML, without any code or tools changes. The task typically runs as part of a copy-resources target.

Typical usage might look like this:

build.xml
<taskdef name="sweetxml" classname="net.innig.sweetxml.ant.SweetXmlTask"> <classpath> <fileset dir="${lib.dir}" includes="sweetxml-*.jar"/> </classpath> </taskdef> <sweetxml <inputFileSet dir="${res.dir}" includes="*.sxml"/> </sweetxml>

Alternatively, if you set Ant up to recognize SweetXML build files (see below), your build might include something like this:

build.sxml
taskdef name="sweetxml" classname="net.innig.sweetxml.ant.SweetXmlTask" classpath fileset dir="${lib.dir}" includes="sweetxml-*.jar" sweetxml inputFileSet dir="${res.dir}" includes="*.sxml"

The Ant task converts SweetXML to XML by default, but can convert in either direction. It will attempt to convert any files you include in the inputFileSet, regardless of their file extension. It is therefore import to include only the files in need of conversion (thus includes="*.sxml" in the example above).

The task accepts one nested element, which is required:

Nested ElementDescriptionDefault
inputFileSet The set of files to convert. Accepts all the parameters of a normal Ant FileSet. required

The task accepts the following attributes:

AttributeDescriptionDefault
mode Conversion mode. Possible values are:
  • s2x: convert SweetXML to XML
  • x2s: convert XML to SweetXML
s2x
outputDir Determines where the converted files will go. same dir as inputFileSet
overwrite If true, the task will overwrite existing files. If false, the task will skip existing files without failing. true
deleteSources If true, the task will remove the input file after converting it. This option is useful if you are converting files in place in a staging directory. Use with caution! false
quiet Reduces the output of the task to critical error messages. false

You may find the command-line interface useful for performing the initial conversion of project files from XML to SweetXML.

Using SweetXML for the Build File

Ant does not have native support for SweetXML. However, it is possible (and much more readable!) to use a build.sxml instead of a build.xml. To do this, you will need to use a wrapper script for Ant which converts your build.sxml, then passes control to Ant.

The SweetXML distribution includes an Ant wrapper script for OS X, Linux, and other UNIX-y OSes, in bin/. (Those of you using MS-DOS are currently on your own; if anybody wants to submit an ant.bat wrapper script, it would be quite welcome!)

Place this script in your path in front of Ant's bin directory, and ant will automatically use build.sxml if it is present. Be careful — if build.sxml exists, it will overwrite build.xml!

The wrapper script requires that you either have ant and sweetxml in your path, or that you set the environment variables ANT_HOME and SWEETXML_HOME.

Table of Contents
innig