TofuBug
TofuBug

Reputation: 603

WIX XMLConfig Different Root Element Names

I'm running into an odd issue with a "config" msi I'm writing in WIX that uses XMLConfig to check for, delete and then create the new values in a single xml file.

Since I Discovered WIX I've been packaging a lot of our manual configuration processes so this is my 7th or 8th time around so i'm fairly comfortable with doing basically the steps above.

This particular case though I've run into a odd situation i'm not sure HOW to make WIX understand.

The same file can change it's root element name depending on the situation

When First Installed:

<DataSet>
    <SomeStuff />
</DataSet>

If Deleted or Changed through installed programs "Settings" dialog

<NewDataSet>
    <SomeStuff />
</NewDataSet>

I'm using VerifyPath to check the delete and Add but it fails with a visible error when the xmlconfig's path is not in the file so even if I had two sets of XMLConfig for each scenario one would visibly error out which is undesirable

A Component Snippet is below

<Component Id="C_MobileSettings" Guid="" KeyPath="yes">
    <CreateFolder Directory="MOBILEINSTALLLOCATION" />
    <XmlConfig 
        Id="MobileSettings_Key_Delete" 
        Action="delete" 
        ElementPath="//NewDataSet/GeneralSettings" 
        File="[MOBILESETTINGSPATH]" 
        Name="Key" 
        Node="element" 
        On="install" 
        Sequence="1" 
        VerifyPath="//NewDataSet/GeneralSettings/Key"  
        xmlns="http://schemas.microsoft.com/wix/UtilExtension" 
    />
    <XmlConfig 
        Id="MobileSettings_Key_Add" 
        Action="create" 
        ElementPath="//NewDataSet/GeneralSettings" 
        File="[MOBILESETTINGSPATH]" 
        Name="Key" 
        Node="element" 
        On="install" 
        Sequence="1" 
        Value="Product Key"
        xmlns="http://schemas.microsoft.com/wix/UtilExtension" 
    />
</Component>

This config msi needs to be able to run at any point post software installation regardless of the state of the root element name.

Is this possible with straight WIX or am I going to have to write a custom action?

Upvotes: 0

Views: 190

Answers (2)

halfer
halfer

Reputation: 20469

(Posted on behalf of the question author).

For the sake of anyone else who happens by here, is how I fixed this using the great suggestion from Adam:

<util:XmlConfig 
    Id="MobileSettings_Key_Create" 
    Action="create" 
    ElementPath="//(NewDataSet | DataSet)/GeneralSettings/Key" 
    File="[MOBILESETTINGSPATH]" 
    Node="value" 
    On="install" 
    Sequence="1" 
    VerifyPath="//(NewDataSet | DataSet)/GeneralSettings/Key" 
    Value="[PRODUCTKEY]" 
/>

After a solid month of repackaging horribly written third part installers it's a nice change to have a solution to SOMETHING be this simple and elegant. A fleeting moment of Zen, but Zen none the less.

Upvotes: 0

Adam Finley
Adam Finley

Reputation: 1620

I don't believe you'll need a custom action. XmlConfig::ElementPath is an XPath and you can use the | (union) operator to have a single action that affects xml nodes of either name.

Upvotes: 1

Related Questions