Reputation: 9695
I use Wix 3.8 and I am able to successfully update values inside XML .config files using XmlConfig
<util:XmlConfig Id="..."
File="[INSTALLFOLDER]unity.config"
Action="create"
Node="value"
On="install"
ElementPath="/configuration/unity/..."
Value="[SOME_PROPERTY]" />
My goal is to insert not just a text value, but a whole XML chunk.
I know I can use multiple XmlConfig statements connected by ElementId attribute for building an XML structure. This does NOT suit me.
The actual XML structure to insert is defined only at the time of installation, so I can't possibly guess how structure of XmlConfig elements should look like during build time.
I get this XML structure into [SOME_PROPERTY] as text, which is actually a valid XML code. How can I insert it into an existing node in .config file?
An example of simple C# Custom Action would suit me, but I thought maybe there is a standard way of doing this like XmlConfig or some other Wix extension...
Upvotes: 1
Views: 554
Reputation: 11
Its simpler than you think, just include the XML snippet as a CDATA section within the Content of the XmlConfig element, i.e.
so lets say you have a structure like:
<root>
<child name="test"/>
</root>
Then you could do the following to add a child with the name test2 to the parent node "root".
The important part is that in the ElementPath you have to put an Xpath that selects the parent node, and you have to omit the Value attribute, and instead put it inside the element body of the XmlConfig element, and if its Xml you want to insert, you have to wrap it in a CDATA section.
Just like below
<util:XmlConfig Id="..."
File="[INSTALLFOLDER]unity.config"
Action="create"
Node="document"
On="install"
ElementPath="//root"
>
<![CDATA[<child name="test2"/>]]>
</util:XmlConfig>
Upvotes: 1