Project:This information applies to the following project types:
Application and configuration settings are sometimes stored in XML files. Use the System Search view to define a search for data in an XML file that may exist on the target system at run time. You can search for a specific attribute, a specific element, or a specific element content string. The results are stored in a property; you can use that property in an installation condition, as the destination for a component in your installation, or in other areas of your installation.
This section presents an example that shows how to search for XML data on target systems at run time. For this example, the product called MyProduct has an executable file called MyProduct.exe. The path for this .exe file is written to a file called Configuration.xml at run time.
Tip:For information on how to use properties to change XML files at run time, see Using Windows Installer Properties to Dynamically Modify XML Files.
Following is sample code from the Configuration.xml file:
<?xml version="1.0" encoding="utf-8"?>
<requiredRuntime version="1.0.0" safemode="true" />
<add value="MyProduct" path="C:\Program Files\MyCompany\MyProduct\MyProduct.exe"/>
The value of the path attribute in the above XML code depends on where end users install MyProduct.
The main objective of this example is to find the value of the path attribute and store that value in a property.
To configure the system search for the XML data:
|1.||In the View List under Behavior and Logic, click System Search.|
|2.||Right-click the grid and then click Add. The System Search Wizard opens.|
|3.||Complete each of the wizard panels as follows:|
|a.||On the What do you want to find? panel: In the list, select XML file value.|
|b.||On the Specify the file details panel:|
|•||In the File Name box, type the following:|
|•||In the Look In area, select A full path, and type the following path:|
|c.||On the Specify the data panel:|
|•||In the XPath to XML Element box, type the following XPath expression:|
|•||In the Look For area, select Value of Attribute in this Element, and type the following in the Attribute Name box:|
|d.||On the What do you want to do with the value? panel:|
|•||In the Store the value in this property box, type the following:|
|•||In the Additional Options area, select Just store the value in the property.|
You can use the value of the search property in another area of your project. For example, to display the value of the property in a dialog in your installation, add a text control to the dialog, and set the Text value of the control to something like this:
PATH_IN_XML_FILE = [PATH_IN_XML_FILE]
If the value of the path attribute in the XML file is C:\Program Files\MyCompany\MyProduct\MyProduct.exe, the dialog displays the following text:
PATH_IN_XML_FILE = C:\Program Files\MyCompany\MyProduct\MyProduct.exe