XmlProperty

Description

Loads property values from a well-formed xml file. There are no other restrictions than "well-formed". You can choose the layout you want. For example this XML property file:

  <root>
    <properties>
      <foo>bar</foo>
    </properties>
  </root>
is roughly equivalent to this Java property file:
  root.properties.foo = bar

By default, this load does no processing of the input. In particular, unlike the Property task, property references (i.e., ${foo}) are not resolved.

Semantic Attributes

Input processing can be enabled by using the semanticAttributes attribute. If this attribute is set to true (its default is false), the following processing occurs as the input XML file is loaded:

For example, with semantic attribute processing enabled, this XML property file:

  <root>
    <properties>
      <foo location="bar"/>
      <quux>${root.properties.foo}</quux>
    </properties>
  </root>
is roughly equivalent to the following fragments in a build.xml file:
  <property name="root.properties.foo" location="bar"/>
  <property name="root.properties.quux" value="${root.properties.foo}"/>

Parameters

Attribute Description Required
file The XML file to parse. Yes, or a nested resource collection.
prefix The prefix to prepend to each property No
keepRoot Keep the xml root tag as the first value in the property name. No, default is true.
validate Validate the input file (e.g. by a DTD). Otherwise the XML must only be well-formed. No, default is false.
collapseAttributes Treat attributes as nested elements. No, default is false.
semanticAttributes Enable special handling of certain attribute names. See the Semantic Attributes section for more information. No, default is false.
includeSemanticAttribute Include the semantic attribute name as part of the property name. Ignored if semanticAttributes is not set to true. See the Semantic Attributes section for more information. No, default is false.
rootDirectory The directory to use for resolving file references. Ignored if semanticAttributes is not set to true. No, default is ${basedir}.
delimiter Delimiter for splitting multiple values.
since Apache Ant 1.7.1
No, defaults to comma

Nested Elements

xmlcatalog

The <xmlcatalog> element is used to perform entity resolution.

any resource or single element resource collection

The specified resource will be used as input.

Examples

Non-semantic Attributes

Here is an example xml file that does not have any semantic attributes.

   <root-tag myattr="true">
    <inner-tag someattr="val">Text</inner-tag>
    <a2><a3><a4>false</a4></a3></a2>
   </root-tag>
default loading

This entry in a build file:

   <xmlproperty file="somefile.xml"/>
is equivalent to the following properties:
   root-tag(myattr)=true
   root-tag.inner-tag=Text
   root-tag.inner-tag(someattr)=val
   root-tag.a2.a3.a4=false
collapseAttributes=false

This entry in a build file:

   <xmlproperty file="somefile.xml" collapseAttributes="true"/>
is equivalent to the following properties:
   root-tag.myattr=true
   root-tag.inner-tag=Text
   root-tag.inner-tag.someatt=val
   root-tag.a2.a3.a4=false
keepRoot=false

This entry in a build file:

   <xmlproperty file="somefile.xml" keepRoot="false"/>
is equivalent to the following properties:
   inner-tag=Text
   inner-tag(someattr)=val
   a2.a3.a4=false

Semantic Attributes

Here is an example xml file that has semantic attributes.

  <root-tag>
    <version value="0.0.1"/>
    <build folder="build">
      <classes id="build.classes" location="${build.folder}/classes"/>
      <reference refid="build.classes"/>
    </build>
    <compile>
      <classpath pathid="compile.classpath">
        <pathelement location="${build.classes}"/>
      </classpath>
    </compile>
    <run-time>
      <jars>*.jar</jars>
      <classpath pathid="run-time.classpath">
        <path refid="compile.classpath"/>
        <pathelement path="${run-time.jars}"/>
      </classpath>
    </run-time>
  </root-tag>
default loading (semanticAttributes=true)

This entry in a build file:

   <xmlproperty file="somefile.xml" keepRoot="false"
                semanticAttributes="true"/>
is equivalent to the following entries in a build file:
  <property name="version" value="0.0.1"/>
  <property name="build.folder" value="build"/>
  <property name="build.classes" location="${build.folder}/classes" id="build.classes"/>
  <property name="build.reference" refid="build.classes"/>

  <property name="run-time.jars" value="*.jar"/>

  <path id="compile.classpath">
    <pathelement location="${build.classes}"/>
  </path>

  <path id="run-time.classpath">
    <path refid="compile.classpath"/>
    <pathelement path="${run-time.jars}"/>
  </path>
includeSemanticAttribute="true"

This entry in a build file:

   <xmlproperty file="somefile.xml"
                semanticAttributes="true" keepRoot="false"
                includeSemanticAttribute="true"/>
is equivalent to the following entries in a build file:
  <property name="version.value" value="0.0.1"/>
  <property name="build.folder" value="build"/>
  <property name="build.classes.location" location="${build.folder}/classes"/>
  <property name="build.reference.refid" refid="build.classes"/>

  <property name="run-time.jars" value="*.jar"/>

  <path id="compile.classpath">
    <pathelement location="${build.classes}"/>
  </path>

  <path id="run-time.classpath">
    <path refid="compile.classpath"/>
    <pathelement path="${run-time.jars}"/>
  </path>