xmlfile
Supports configurable merging of well-formed XML files. As well as allowing one-way merges (specified individually, or in bulk from a source fileset to a destination directory), <xmlfile> also allows merging of multiple source files to a single destination file.
The processing engine for XML file merging is an integrated version of the xmlmerge module from the EL4J framework. The configuration options for merging reflect the functionality of this framework. It is not possible to explicitly add completely new markup to an XML file using this task, although fine-grained configuration of the merging operation is provided by xmlmerge.
Parameters
| Attribute | Description | Required |
|---|---|---|
| fromfile | The source XML file. | No. Nested <fileset> elements can also supply the merge source(s). If specified, fromfile must exist. |
| tofile | The XML file to merge to. | Exactly one of these is required. Similar to the Ant copy task, |
| todir | The directory to patch to. | |
| targetfile | An alternative file to write the merged XML to. | No. When specified, tofile itself is not modified. Cannot be used when nested <fileset>s or todir are specified (since it makes no sense). |
| preservelastmodified | Give the new XML file(s) the same last-modified time as the original source file(s). | No; defaults to false. |
| overwrite | Allow existing target files to be overwritten. | No; defaults to false. If overwrite and create are both set to false, an error occurs. |
| create | Allow target files to be created where they don't already exist. | No; defaults to true. If overwrite and create are both set to false, an error occurs. |
| cleanup | Deletes original XML file(s) after new merged file(s) is/are successfully written. If any destination or target file could not be processed or written for any reason, the original file is never deleted, even if this is set to true. | No; defaults to false. |
| failonerror | If false, the listener will try to continue processing remaining actions even when errors in reading, processing, or writing files occur. Instead of immediately failing, a warning message is written to the log. | No; defaults to true. |
| enablemultiplemappings | If true the task will process to all the mappings for a given source path. If false the task will only process the first file or directory. This attribute is only relevant if there is a mapper subelement. | No; defaults to false. |
| condition | Specifies the name of an IzPack installer condition that must be fulfilled before the configuration is executed. | No. |
| configfile | Specifies the path to a plain Java property file (i.e. line-separator-delimited key=value properties) that specifies any number of merge configuration directives (see <xpathproperty>, below). | No. Cannot be used if {{>< |
Nested Elements
The following nested elements can be specified to configure, and define the scope of, XML merging operations.
xpathproperty
The nested <xpathproperty> element is used to override the default XML merging handling of a certain XML content. Each key value ends either on .default (just one is allowed, and is not applicable to xpath.) or .<number>, where all keys with the same ending <number> are assigned to one and the same element matching xpath.path.<number>.
Attribute | Description | Required |
|---|---|---|
key | The XPath property key to deal with. | Yes. Valid values are:
|
value | The XPath property value to set the above key value to. Using
Using
Using
Using | Yes. Defaults are listed here.
|
fileset
Specifies patch source files using one or Ant-style <fileset> elements. See the description of the <fileset> element. Can be used with the parameters tofile/targetfile to specify that many files are to be merged into one file.
mapper
Defines one or more file name transformations to apply to the merging execution. See the description of the <mapper> element. Only one mapper element can be used (use compositemapper to define a chain of transformations).
Examples
Merges two XML files, retaining all values and elements from the source file resources.xml.configbak and discarding matching elements in the destination resources.xml. The source file is deleted after the merge, and the destination file replaced with the new, merged version. The task is only executed when the IzPack condition isUpgrade is fulfilled.
This example uses an external properties file to define merging behavior for two XML files. The default behavior attempts to merge all matching elements and attributes in the two XML files. Three exceptions are defined for elements matching specific XPath condition. XPath path1 is matched by element name and the value of attribute name, and copies in the element from the source file, completely replacing the version in the destination file; XPath path2 is matched by element name and the value of attribute ID, and also is subject to the REPLACE action; XPath path3 is also matched on element name and attribute ID, and retains only destination file elements with matching source file elements.