How do I create or modify an existing XML file as part of my MSI or Transform using InstallShield?
I have found that creating or modifying an existing XML within InstallShield as part of an Installation can be challenging. After multiple attempts to figure this out on my own I took to Google, yet ran into more confusion within the online community…
I am not sure whether Flexera intended it to be this difficult, but it sure was challenging at first. Although, perhaps being somewhat of an amateur at the time, might have been a factor…
After multiple attempts and Google searches I eventually accomplished what I set out to achieve.
Firstly, I needed to create my component, which was the .xml file itself. Unless you’re using InstallShield to modify an existing .xml that is part of the Installation already, you will also need to do this.
There are two ways to create your .xml file;
Option (A) (Let the Installer create the component for you)
Select “XML File Changes” > Right Click XML Files > Select New File
You should now see a new Component within the Components section that is the name you called your .xml file.
If you’re seeing a small red exclamation mark against your newly created component like mine above, this indicates you have not yet associated this component with your installers Setup.
To do this, find your Setup and select Associate Components > Browse to the Component and add it to your Setup. As you will see, I created a Setup earlier for myself, called Setup.
(If you do not do this, your component will not be created on your target machine upon installation)
If your MSI already contained an .xml file or if you already added the .xml file to your File and Folders structure, you should see it already existing as a Component within your MSI like so.
Before I continue, something worth mentioning. To confirm the installation path of where your .xml file is going to reside, select your component and see the Destination value. Mine is obviously going to reside within the Install Directory of my package.
I decided to allow InstallShield to create the Component for me. So, I chose to go with Option (A) for this Tutorial.
Moving on, we need to Create our .xml Element structure. In this example, I am going to create it from scratch. Open “XML File Changes” from InstallShield’s menu to the left. Right Click your .xml file and select New Root Element. Mine is already created, hence why it is greyed out in my screenshot below.
Now Right Click to do the same to create your Sub Elements
Once you have finished creating your .xml structure, over to the right you will see two Tabs. General and Advanced.
Select General, and for each .xml Element you can create your Value. The Attribute will be the same name as your Element, the Value is obviously your Value, Operation tells the Installer what to do (I want to “Create” the Element Attribute within the .xml file itself) and Scheduling determines when this .xml Value is written (Upon installation).
Go through each Element to create your Values.
Now flip over to the Advanced Tab.
This section is rather self-explanatory, I want these Values and Elements to be created within the .xml file if they do not already exist. I also uncheck the Remove element on uninstall because It does not need to be ticked, because upon uninstallation my .xml file will be removed from the filesystem regardless.
You can also specify further settings by Selecting the .xml file and then the Advanced tab.
Now all of that is pretty straight forward, however, and this is where I became stuck. Even with all this, my MSI was still not writing Values to my .xml file. You would think that this is all that is required, yet I still had to complete the following. Perhaps this will not be the same for you, yet if you run into a similar issue, try the following.
Select the Direct Editor and find the ISXmlElement Table.
You may see your Element’s Content Values are empty like so.
Enter your Values in again, but this time within the Content boxes. See mine below.
You can also specify these Values as Properties which you can pass-thru to be used upon Installation. Here’s oneI I prepared earlier.
I then specified the Values within a Property to which I can see within the MSI’s Property Table or InstallShield’s Property Manager.
After you have updated the ISXmlElement Table and Built your MSI, or saved your Transform. Install your MSI, your Install should now include your .xml file.
Here’s a copy of what mine looks like!