Using InstallScript Text Substitution to Dynamically Modify XML Files

InstallShield 2020

Project:This information applies to InstallScript projects.

For InstallScript projects, you can use a text substitution string variable for an XML element, an attribute, an attribute value, or an element’s content. When the XML file changes occur at run time, the InstallScript run-time code uses the TextSubSubstitute function to replace the string variable with the appropriate value. This enables you to use data that end users enter in dialogs, or other configuration information that is determined during the installation, in your product’s XML files.

Tip:Use text substitution for an element, an attribute, or element content only if the value of the property would make a well-formed XML document. If a property value would lead to syntax errors in the XML document, your product or installation may not behave as expected.

For example, if you set the name of an element to a text substitution string variable that will be replaced with text that includes one or more spaces, end users may have problems with your product or your installation. Element names cannot contain spaces, and XML documents that contain element names with spaces are not valid.

Note:If test your XML file from within the XML File Changes view, any text substitution string variables that are used for XML data are not replaced with the appropriate values during testing. For more information about testing, see Testing Installation Changes to an XML File or Testing Uninstallation Changes to an XML File.


The following procedure demonstrates how to use the name of the SQL Server that an end user selects in the SQL Login dialog as the content for one of the elements in your XML file. Note that you can substitute a hard-coded value with a text substitution string variable for any of the elements, attributes, attribute values, or element content in the XML File Changes view. The string variable that you specify in this view must be enclosed within angle brackets; for example, <MYPROPERTY>. The string variable that you specify is case-sensitive.

To use the name of the SQL Server that end users select as the content for an XML element:

1. Configure the SQL connection and any associated SQL scripts if you have not already done so:
a. In the View List under Server Configuration, click SQL Scripts.
b. Add a SQL connection and SQL scripts as needed. For instructions, see Configuring SQL Support.
2. In the View List under System Configuration, click XML File Changes.
3. In the XML Files explorer, select the element to which you want to add content.
4. Select the Advanced tab.
5. Select the Set element content check box.
6. In the Content box, type the following:


7. In the View List under Behavior and Logic, click InstallScript.
8. Find the dialog code in the OnSQLLogin event for the SQL Login dialog that contains the SQL Server control, and add a call to the InstallScript function TextSubSetValue. For example:

// Display login dialog (without connection name)


nResult = SQLServerSelectLogin2( szConnection, szServer, szUser, szPassword, bWinLogin, szDB, FALSE, TRUE );

TextSubSetValue("<MYPROPERTY>", szServer, TRUE);

9. Build your release.

See Also