jdixon
Posts: 18
Joined: Sat Jan 04, 2014 8:50 pm

Keeping XML elements (Multiple siblings)

I have an XML that I need to retain data. Currently I have a search and store those in a public variable which I use in the XML file. The problem is I have one element that has many child elements that can be put in by the user that need to be retained. I cannot figure out how to get this data and store it in a variable so it is retained during upgrades!

Example XML:

Code: Select all

<Tester>
  <Events>
    <Event attribute1="" attribute2="" attribute3=""></Event>
    <Event attribute1="" attribute2="" attribute3=""></Event>
    <Event attribute1="" attribute2="" attribute3=""></Event>
    <Event attribute1="" attribute2="" attribute3=""></Event>
  </Events>
  <Mail>
    <Server></Server>
    <Port>25</Port>
    <EnableSSL>false</EnableSSL>
    <Username></Username>
    <Password></Password>
    <From></From>
    <To></To>
    <Subject></Subject>
  </Mail>
  <FriendlyName></FriendlyName>
</Tester>
Notice all the <Event> elements under the <Events> node. How do I maintain all of that? Those elements are added by the user so there could be 2 event elements o there could be 25 event elements. I tried to get the Element Text for "Events" but that didn't work.
Eusebiu
Posts: 4964
Joined: Wed Nov 14, 2012 2:04 pm

Re: Keeping XML elements (Multiple siblings)

Hi,

I'm afraid that the whole "Events" node cannot be stored in a public property. However, in order to preserve the updated XML file, you can follow the steps below:
- add your XML file as a Windows Installer (XML Edit) file in the "Files and Folders" page
- do the updates you need to that file
- add it as a regular file, too and check the "Do not overwrite existing file" option for it

During the first install the XML file will be copied on the user's machine and the updates you configured will be applied to it. During an upgrade, the updated file will be preserved along with the "Events" node, but no updates can be applied to it anymore because the file from the user's machine is backed up before the upgrade and restored after the upgrade.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”