t3knoid
Posts: 21
Joined: Wed May 27, 2015 8:15 pm

Overwriting an XML Element value with a blank value

I can't seem to overwrite an XML element's value with a blank one. My installer uses an XML Element for the application configuration file whose element values are overwritten dynamically during install depending on some criteria.

For example, let's say I have the following default value in my application config:

<setting name="SETTINGA" serializeAs="String">
<value>myvalue</value>
</setting>

There is a corresponding XML element that is set using a property, lets call it MYVALUEPROP. A custom action initializes this property to some value. The value can either be a blank or non-blank. When it is a non-blank, the default SETTINGA value is overwritten with whatever MYVALUEPROP was set to in the custom action. However, if the value is blank, the SETTINGA value maintains its value of "myvalue." I expect it to be empty since MYVALUEPROP is set to empty.
t3knoid
Posts: 21
Joined: Wed May 27, 2015 8:15 pm

Re: Overwriting an XML Element value with a blank value

This is a real dilemma. I just realized that setting a property to empty basically deletes the property. That's why the old setting is never getting over written. I can set the value to a space. That works and the old value gets overwritten with a space, but that is not exactly the same as empty. The real question is how to create a property that has an empty value?
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Overwriting an XML Element value with a blank value

Hello,

You can set an installer property to have an empty value by using a "Set installer property" custom action/dialog control. For instance, you can proceed as it follows:

-Go to "Dialogs" page, click on "WelcomeDlg", select the "Next" button, press "New..." --> "Set installer property value" with the following arguments:

Code: Select all

Property: YOUR_PROPERTY
Argument: {}
Condition:1
Now, after the upgrade process, your XML file should look like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<setting serializeAs="String" name="SETTINGA">

<value/>

</setting>
Hope this helps.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
t3knoid
Posts: 21
Joined: Wed May 27, 2015 8:15 pm

Re: Overwriting an XML Element value with a blank value

Thanks for your reply.

Before you posted this suggestion, I actually tried setting the property to {} in a custom action (in the InstallExecuteSequence before). All it does is delete the property. It's doing the same thing with what you've suggested. I don't even see the property being initialized in the log file. The only time that I see it if I initialize the property in the Install Parameters section with some value. When it hits the setting the property to {}, the log states that the property is being deleted.

To give you some context, here are the relevant entries in my aip file:

Line 426: <ROW Dialog_="WelcomeDlg" Control_="Next" Event="[MYVALUEPROP]" Argument="{}" Condition="AI_INSTALL" Ordering="2"/>
Line 688: <ROW XmlAttribute="name_38" XmlElement="setting_36" Name="name" Flags="15" Order="0" Value="SETTINGA"/>
Line 814: <ROW XmlElement="value_36" ParentElement="setting_36" Name="value" Condition="1" Order="0" Flags="14" Text="[MYVALUEPROP]"/>

In my app.config file, I have the following entry that I am trying to set to empty:

<setting name="SETTINGA" serializeAs="String">
<value>My old value</value>
</setting>

To clarify, the custom action that sets the property skips setting the MYVALUEPROP if it is empty. So basically the only custom action that sets the MYVALUEPROP property is the one that was added in the WelcomeDlg Next button.
t3knoid
Posts: 21
Joined: Wed May 27, 2015 8:15 pm

Re: Overwriting an XML Element value with a blank value

I just re-read the documentation and realize there is ans xml test feature.

https://www.advancedinstaller.com/user- ... -test.html

I ran this test on the config file that it is supposed to modify. It basically performed as I've already observed:

- Settings that are being set with properties have defined values are getting modified.
- Settings that are being set with properties that is null are not getting modified.

Right now, the only way I can see this working is to delete the settings from my app.config the ones I want to blanked pre-build time.
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Overwriting an XML Element value with a blank value

Hello,

First of all, thanks for the additional information. It seems that I have tested a complete different scenario.

Indeed, after re-testing this, I was able to reproduce the behavior you have described. This seems to be an issue in what regards Advanced Installer. I have forwarded this to the developers team and we will further investigate it.

Unfortunately, I am not aware of any workaround that will overcome this issue at the moment.

I will update this thread as soon as we have a conclusion.

Thanks for your understanding.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
t3knoid
Posts: 21
Joined: Wed May 27, 2015 8:15 pm

Re: Overwriting an XML Element value with a blank value

Thanks for confirming. I'll await for what development has to say. In the meantime, I ended up writing a utility that I run post-build. The utility simply blanks out the property values. It's a bit hacky, but it works. If anyone is interested, I shared the code here (C#). It's pretty specific to my needs. However, it should be enough to get you started to write your own.

https://github.com/t3knoid/SetSettingToBlank
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Overwriting an XML Element value with a blank value

Thank you for sharing the code that helped you achieve what you wanted. I am sure it will be of help for further users facing similar scenario.

In what regards the development team, I will update this thread as soon as we come to a conclusion.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: Overwriting an XML Element value with a blank value

Hello,

This was fixed in version 15.6 of Advanced Installer released on January 8th, 2019.

Kind regards,

Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”