Merging XML Files
Add new XML to XML files with the XML file merge package fragment installer
The XmlFileMergePackageFragmentInstaller allows you to merge two XML files, that is, introduce some new XML into XML files (for example, web.config).
New child elements and new attributes are imported to a target file from a source file. Conflicts are ignored and not merged.
This is the simplest way to add XML to XML files on the website and can be used for updating configuration files instead of XSLT (via FileXslTransformationPackageFragmentInstaller).
The XmlFileMergePackageFragmentInstaller uses XML in a source XML file from the package and merges it with XML in a target file on the website. Uninstalling the package will remove the merged XML from the target file.
Please note that while you can use this fragment installer to also merge XML on an existing element (for example, adding another attribute), it can lead to undesirable results when uninstalling the package - removing the original XML if matched.
<mi:Add installerType="Composite.Core.PackageSystem.PackageFragmentInstallers.XmlFileMergePackageFragmentInstaller, Composite" uninstallerType="Composite.Core.PackageSystem.PackageFragmentInstallers.XmlFileMergePackageFragmentUninstaller, Composite"> <XmlFileMerges> <XmlFileMerge targetFilePath="~\test1.xml" changeDefinitionPath="~\xml\merge1.xml" /> <XmlFileMerge targetFilePath="~\App_Data\test2.xml" changeDefinitionPath="~\xml\merge2.xml" /> </XmlFileMerges> </mi:Add>The
XmlFileMerges
element can contain one or more
XmlFileMerge
elements.
The XmlFileMerge
element has the following attributes:
changeDefinitionPath
: A tilde-based path that points to a file in the package's ZIP. It contains XML to be added to the target file.targetFilePath
: A tilde-based path that points to a file location on the C1 CMS - the target file
Here is an example of the target file - the file to be updated on the website:
<?xml version="1.0" encoding="utf-8"?> <root> <element name="one">Element 1 content</element> <element name="two">Element 2 Content</element> </root>Here is an example of the source definition file - the file containing XML to be merged into the target file:
<?xml version="1.0" encoding="utf-8"?> <root> <element name="three">Element 3 content</element> <element name="four">Element 4 Content</element> </root>