don't overwrite xml value - Advanced Installer Community
entilz
Posts: 1
Joined: Wed Apr 16, 2014 3:05 pm

don't overwrite xml value

Hi
I have a problem with editing config file (xml) I would like to add new value to xml file but don't overwrite the old ones

preconditions:
xml file structure

appSettigns
kay
value:7777
appSettigns
kay
value


Steps to reproduce:
1. Import config file (xml)
2. Create setup.exe
3. Install application with config file
4. Go to installed application and change config file entry appSettings value:7777 on value:77776
5. Go to installer
6. Go to imported config file
7. Imported file structure:
appSettigns
kay
value: 7777
8. check in elements settings Create element if it doesn't already exist
unselect in elements settings: If element is found:
9. Add new appSettings at the bottom of the list
10. Go to Product Detail
11. Update version number
12. Build
13. Install new version

Expected Result:
value with unselected 'if element is found' is not ovewritten 77776
new appSettings element is added

Actual Result:
Value with unselected 'if element is found' is ovewritten 7777
new appSettings element is added
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: don't overwrite xml value

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

Please keep in mind this is the normal behavior if you have built your increased version as a major upgrade. During a major upgrade it is first removed the old version of the product (so the XML file is removed) and, then it is installed the new version of the product which will not found the old XML file and will install all elements of the new one.

However, in order to achieve what you want you can configure your XML file and its elements not to be removed on uninstall. Here are the steps to proceed:
- open your first project
- go to "XML File Install Tab" and uncheck the "Remove file on uninstall" option
- select your XML elements and uncheck the "If the element is found" and "Remove element on uninstall" options from "XML Element Settings Tab"
- build and run your first project
- open the upgraded project and add a new "appSettigns" element to the XML file
- for the last added "appSettigns" element enable the "If the element is found -> Add as new sibling" option
- build and run your upgraded project

Also, I've attached a sample created with version 11.0 of Advanced Installer which implements a similar scenario.
sample.zip
(7.46 KiB) Downloaded 339 times
If you have any questions just let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Zsolt Kollarits
Posts: 409
Joined: Fri May 29, 2015 10:36 am

Re: don't overwrite xml value

Hi Daniel,

I found this thread exactly talking about a scenario we are also working on:
viewtopic.php?p=97255&sid=5dcff8b1a8971 ... 77d#p97255

Your sample.zip gave us some ideas, but it´s not 100% working for us. We have several version of our product, our customers are on different versions and they might skip some version when upgrading their old systems.

Let´s assume there are 3 versions: 1.0, 2.0 and 3.0

Version 1.0: Based on your sample.aip it contains one value node (kay) with value 7777. "If the element is found" is disabled.

Version 2.0: Based on your sample 2.aip it contains two value nodes (kay),
1st has the value 7777. "If the element is found" is disabled
2nd has the value 22222222. "If the element is found" is set to "Add as new sibling

Installing Version 2.0 over 1.0 is working as expected, the 1st kay node is untouched, the 2nd kay node is appended after the 1st.


Version 3.0: I created 2 separate 3.0 projects:

a) sample 3 _ add middle kay as new sibling.aip
1st has the value 7777. "If the element is found" is disabled
2nd has the value 22222222. "If the element is found" is set to "Add as new sibling
2nd has the value 33333333. "If the element is found" is set to "Add as new sibling

Installing Version 3.0 over 1.0 is working as expected, the 1st kay node is untouched, the 2nd AND 3rd kay nodes are appended after the 1st.
Installing Version 3.0 over 2.0 is NOT working as expected, the 1st kay node is untouched, the 2nd kay node is DUPLICATED, since Version 2.0 already appened it. So there are 4 nodes in total instead of 3, this is an issue of course.

b) sample 3 _ do not update middle kay.aip
1st has the value 7777. "If the element is found" is disabled
2nd has the value 22222222. "If the element is found" is disabled
2nd has the value 33333333. "If the element is found" is set to "Add as new sibling

Installing Version 3.0 over 1.0 is NOT working as expected, the 1st kay node is untouched, the 2nd kay node is MISSING, the 3rd kay node is appended. The missing 2nd node is an isssue of course.
Installing Version 3.0 over 2.0 is working as expected, the 1st and 2nd kay nodes are untouched, the 3rd kay node is appended.


Please check the 2 new version 3.0 projects I created, everything is included in the attached zip file.

As you can see no matter how I tried to modify my sample 3 project, either upgrade from 1.0 to 3.0 or upgrade from 2.0 to 3.0 is failing. There is no reliable sample 3 yet which would work under all circumstances. Obviously the more product versions are causing more problems.

Could you please have a look at the samples? We need some stable/fixed settings at "Edit XML File" dialog that would always work, so that we could use the same settings for each of our releases. We do not want to refresh the Element Settings for each node before every release

Thanks in advanced!

Best regards,
Zsolt
Attachments
sample from Zsolt.zip
(16.01 KiB) Downloaded 301 times
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: don't overwrite xml value

Hello Zsolt,

The only solution for you in this case I can think of is to use XML searches to detect if the second and third XML elements exists, and to use the XML search properties in the "Condition" field of your second, third, etc. XML elements. This way the subsequent XML elements won't be installed unless they do not exist in previous version of the XML.

Also, you should use the "If the element is found" option set to "Add as new sibling".

Hopefully this will cover all the scenarios you could encounter at installtime. :)

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Zsolt Kollarits
Posts: 409
Joined: Fri May 29, 2015 10:36 am

Re: don't overwrite xml value

Hi Daniel,

I´m aware of the option looking for all the XML nodes via XML searches and save all the values into properties. Then use those properties as conditions at Edit XML dialog. This means we have to always ask our developers for all the change in their .config files and modify our .aip project before each of our releases. Obviously these kind of modifications can cause lot of issues, for example if we forget to add an XML search for a particular node, then the node will be gone on the customer´s PC after he upgraded our product.

That´s why we´d need a more "bulletproof"/lightweight solution. That´s why I was happy when found this thread with your sample.zip, the .aip projects in your .zip seemed to be working in an easy way without XML searches. Could you please think about a solution without XML searches and without the necessity of adding/removing nodes every time before we release a new version?

Best regards,
Zsolt
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: don't overwrite xml value

Hello Zsolt,

I'm afraid there is no other bullet proof solution you could implement to achieve what you need. Maybe you could talk with your developers to change the structure of your XML so that each XML element could be uniquely identified in the XML tree.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”