|
9.2. Loading Properties from XML FilesThe xmlproperty task loads property values from a well-formed XML file. The way you structure the XML document determines the names of the properties it creates. Say you have this XML document, properties.xml, that defines a property named name1, and two nested properties, firstName and lastName, creating the properties name1.firstName and name1.lastName: <name1 language="english"> <firstName language="german">Stefan</firstName> <lastName>Edwards</lastName> </name1> You can load these properties into a build with the xmlproperty task, as shown in Example 9-3. This build file displays the values of the properties created by properties.xml, name1.firstName, and name1.lastName. This example defines attributes for the name1 and firstName properties, creating an attribute named language which can be accessed as name1(language) and as name1.firstName(language). The build file displays the values of these properties. Example 9-3. Loading XML properties (ch09/xmlproperty/build.xml)<?xml version="1.0" ?> <project default="main"> <xmlproperty file="properties.xml" /> <target name="main"> <echo> ${name1(language)} ${name1.firstName} ${name1.firstName(language)} ${name1.lastName} </echo> </target> </project> Here's what the build file displays when run: %ant Buildfile: build.xml main: [echo] [echo] english [echo] Stefan [echo] german [echo] Edward [echo] BUILD SUCCESSFUL Total time: 0 seconds The attributes of this task appear in Table 9-5.
|
|