PDA

View Full Version : Reading XML from .Net configuration file.



Hamilton-Scott
03-05-2006, 06:11 AM
I have a .Net application configuration file that contains:

<appSettings>
<add key="Address" value="ABCDE"/>
</appSettings>

I want to do a system search to get the value of the Address. What I can't work out is how to setup an XML system search to accomplish it. I've tried using most of the options in the system search (there are'nt many variations) but no matter what I try I always get a null value in the property. :confused:

Can someone help me?

Edit: I 'solved' this problem in the past by using the xmldoc object in VBscript and I need to do XML reading in another project. Surely the system search can do what I want to do? I also tried the KB article that reads XML using 10.5 but this does not work in 11.0 and I've compared the screenshots in the KB to the dialogs in my project. Here's the link (http://www.installshield.com/news/newsletter/0412-articles/XmlSearch.asp).

RobertDickau
03-05-2006, 11:42 AM
What are you using as your XPath expression? In the XML Details panel of the System Search Wizard, perhaps use:

/appSettings/add

and specify key in the Attribute Name field.

Hamilton-Scott
03-05-2006, 12:56 PM
Robert,,

following is the extract from the log file. The first XML search is the one I based on the 10.5 KB article. The second is my own hand-rolled one using my XML configuration file and I tried variations of your suggested approach. I've added a property for each into the property manager and I seeded the value with a starting value. The install welcome screen displays the values in the property manager and that's consistent with the messages below which don't change them. I'm leaning to the XPath syntax error but I've never used Xpath before.

Action 17:33:28: Progress Custom Action. Running ISXmlAppSearch...
1: Searching for an XML Attribute value using the Element 'Repositories/Repository[@DisplayName='Local']' and the Attribute 'Path'.
1: Element not found using the following Element: Repositories/Repository[@DisplayName='Local']. It is possible that the element did not exist or the XPath syntax is invalid.
1: Searching for an XML Attribute value using the Element 'appSettings/add[@key='Address']' and the Attribute 'value'.
1: Element not found using the following Element: appSettings/add[@key='Address']. It is possible that the element did not exist or the XPath syntax is invalid.
Action ended 17:33:28: ISXmlAppSearch. Return value 1.

RobertDickau
03-05-2006, 01:04 PM
Perhaps try the XPath expression I posted (and for now delete the default value from the Property table)? I get this in the log file:
Action 11:44:59: Progress Custom Action. Running ISXmlAppSearch...
1: Searching for an XML Attribute value using the Element '/appSettings/add' and the Attribute 'key'.
MSI (c) (40!C0) [11:44:59:380]: PROPERTY CHANGE: Adding VALUE_FROM_XML_FILE property. Its value is 'Address'.
1: Success! The ISXmlAppSearch action set the value of the associated property to the following value: 'Address'.
Action ended 11:44:59: ISXmlAppSearch. Return value 1.

Hamilton-Scott
03-05-2006, 01:18 PM
Robert,

I am getting somewhere. Trying what you suggest works but the devil in the detail is the configuration file. That is, I used a cut-down version of it for display purposes but it can in fact contain many keys, as in:

<appSettings>
<add key="Address" value="uk01wlap192"/>
<add key="AdhocDBClass" value="ApolloDB"/>
<add key="OutputDPI" value="200"/>
</appSettings>

What you described does work if I only have the one key but I need to search for specific keys, such as Address in the sample above.

RobertDickau
03-05-2006, 01:23 PM
Oh, I misunderstood the question... Perhaps try XPath (note the leading slash):

/appSettings/add[@key='Address']

and Attribute Name value...

Hamilton-Scott
03-05-2006, 01:25 PM
Robert,

I seem to have cracked it! The syntax I tried it this:

/appSettings/add[@key='OutputDPI']

and I now get the correct value displayed. I tried using other keys and I get the correct values. I'm not sure why it never worked before so I'll put it down to typos and not checking it properly. All seems ok now. Thanks for your help with the syntax suggestion as it steered me in the right direction.

Edit: Robert, I was busy compiling my post when you replied. I had tried the exact syntax you provided! :)

RobertDickau
03-05-2006, 04:18 PM
Oh, good, I'm glad it's working now---and a little tip: when I'm trying to figure out XPath expressions for an XML file, it's sometimes useful to import the file into the XML File Changes view (in a throwaway project) and look at the Advanced tab...

Christopher Painter
09-19-2006, 03:45 PM
I'm at a new job using IS11 and I'm having a hard time getting this to work. I'm trying to implement a pattern of

1) XML Search to harvast setting of previous uninstalled installation
2) Dialog for user changes
3) Install XML component ( Perm Component)
4) XML Changes

I have 2 3 and 4 working. I took the advice of stealing the XPath from the XML changes view but I get this in my log:


MSI (c) (9C:3C) [15:17:24:138]: Connected to service for CA interface.
Action 15:17:24: Progress Custom Action. Running ISXmlAppSearch...
1: Searching for an XML Attribute value using the Element '/configuration/AppSettings/add[@key="wsConfigurationUrl"]' and the Attribute 'value'.
1: Element not found using the following Element: /configuration/AppSettings/add[@key="wsConfigurationUrl"]. It is possible that the element did not exist or the XPath syntax is invalid.
Action ended 15:17:24: ISXmlAppSearch. Return value 1.

The XML Search page seems to indicate that you can select INSTALLDIR as a place to search for an XML file but the action is scheduled before costing so I don't see how this could be. I copied the XML file to C:\ and referenced it as [WindowsVolume] but still no work. The XPath seems correct. An example of the file is:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="wsConfigurationUrl" value="redacted"/>
</appSettings>
</configuration>

Christopher Painter
09-19-2006, 04:04 PM
Ah, got it. AppSettings != appSettings

As for my costing/sequencing problem, I can see why XMLSearch needs to run before LaunchConditions so I'll have to extend my design to have a perm reg component store the location of the previous installation of the application.

I know developers love XML, but sometimes it just seems like such a pain to implement instead of leaving a couple registry values around.

Christopher Painter
09-19-2006, 04:49 PM
Ok, things are going really good when I use a Component search to feed the location of my .config file. However there is a problem...... ISXMLAppSearch is running again in the execute sequence. This doesn't seem like correct behavior. I can `show all custom actions` and change the execution option, but the default seems like it should be run only once.

Is there a hotfix or fix in newer version of InstallShield for this? I'll have to check it in IS12 when I get home tonight.



MSI (s) (18:B8) [16:22:39:642]: Skipping AppSearch action: already done on client side
Action ended 16:22:39: AppSearch. Return value 0.
MSI (s) (18:B8) [16:22:39:642]: Doing action: ISXmlAppSearch
Action 16:22:39: ISXmlAppSearch.
Action start 16:22:39: ISXmlAppSearch.
MSI (s) (18:4C) [16:22:39:657]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI2502.tmp, Entrypoint: ISXmlAppSearch
MSI (s) (18:40) [16:22:39:657]: Generating random cookie.
MSI (s) (18:40) [16:22:39:673]: Created Custom Action Server with PID 496 (0x1F0).
MSI (s) (18:54) [16:22:39:735]: Running as a service.
MSI (s) (18:5C) [16:22:39:735]: Hello, I'm your 32bit Impersonated custom action server.
Action 16:22:40: Progress Custom Action. Running ISXmlAppSearch...
1: Searching for an XML Attribute value using the Element '/configuration/appSettings/add[@key='wsConfigurationUrl']' and the Attribute 'value'.
MSI (s) (18!80) [16:22:40:079]: PROPERTY CHANGE: Modifying A2SERVERURI property. Its current value is 'REDACTED'. Its new value: 'REDACTED'.
1: Success! The ISXmlAppSearch action set the value of the associated property to the following value: 'REDACTED'.
Action ended 16:22:40: ISXmlAppSearch. Return value 1.

Christopher Painter
09-19-2006, 08:23 PM
Well it seems the default behavior in IS12 is AlwaysExecute also. Since this is an extension of the AppSearch pattern, I think the scheduling should be the same.