cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Pilgrim

XPath and Installscript...

Hello All,

I've been struggling with this for two days now. This ability is barely documented and it's very difficult to get any feedback.

Essentially, i'm trying to replace some values in an XML file:


function string FileStringReplacement(hMSI, sDestPath, sDestFile, sMachineDeviceName)

OBJECT oDoc, Lot;
NUMBER nvFileHandle, nvResult;
STRING svString, szResult, szPath, szFile, szReplace, strTempString;


begin

set oDoc = CreateObject("Msxml2.DOMDocument.4.0");
oDoc.async = FALSE;
oDoc.setProperty("SelectionLanguage", "XPath");

oDoc.load(sDestPath + sDestFile);

set Lot = oDoc.selectNodes("/Device/@Name");

Lot.attributes.getNamedItem("Value").value = sMachineDeviceName;

oDoc.save(sDestPath + sDestFile);
set oDoc = NOTHING;

end;



The XML file:


false
false
5
Datascope.DatascopeDevice
Datascope




Nothing is happening. Any ideas? Please advise, i'm going insane over here... It's scheduled after the files are installed and it's running next to another custom action which is working. So i know it's not a scheduling problem. And i cannot use XMLFileChanges there is to much logic behind what i need to do....

TIA!
Labels (1)
0 Kudos
13 Replies
Highlighted

Re: XPath and Installscript...

I can't imagine why you can't use Xml File Changes. You read in all the XML that you need into properties, do your business logic in InstallScript and then use XML Changes to write all of the properties back.

The key is the hard part ( xpath and supporting rollback ) is handled for you for free while you write a minimal set of code in InstallScript.
0 Kudos
Highlighted
Pilgrim

Re: XPath and Installscript...

BasicMSI,

I thought you retired Chris?

If what i'm doing above can't be done in a Basic MSI, what's your method Chris? Can you be a little specific?

The problem mostly is that i'm generating xml, not just changing it. I'm reading it from one file, and dynamically placing large chunks in another file based on conditions based on several properties.
0 Kudos
Highlighted
Pilgrim

Re: XPath and Installscript...

Any ideas?
0 Kudos
Highlighted

Re: XPath and Installscript...

I'd have to see everything to give you a full opinion. Certainly you can put your chunks on in different components and then use conditions on those components to drive what gets written. Seems possible but I'm sitting over here...
0 Kudos
Highlighted
Pilgrim

Re: XPath and Installscript...

What Chris suggested should work in you case. Since you are going to create a xml, what I can see here is to import a skeleton xml (right click on 'xml file change' then ->Import, a wizard would show up), you might put some tokens in it, after importing, you can change element/attributes on how you would like it to be handled via 'Operation' and "scheduling' under General tab, and tweak Element Properties under Advance tab.
0 Kudos
Highlighted
Pilgrim

Re: XPath and Installscript...

Essentially,

Users select from a combobox which system they intend to use. 1 out of 7.

Based on that dropdown, a bunch of other textedit fields appear and take in information about those options. Each are global properties. So unfortunately, they can select up to 4 machines.

So we are now up to 7 possible types. Each of these types has it's own xml file. The master xml file sits in an outside directory. (But installed with the product also.)

/Settings
7 xml specific files with multiple nodes.

/
1 master.xml file.

So let's say someone chooses machine 1 as their first machine, i need to grab the text from settings/machine1.xml and place it in master.xml and replace the values with properties set from the dialogs.

Then they can select three more machines, which need to copy 3 more sections of xml into the master.xml file, and change their properties based on global properties also collected from the dialog.

You guys are telling me this is all possible via xmlchanges section? What am i missing? lol...

I've got the properties coming through customactiondata tokenized. No problem getting them over to the differed sequence. Just can't find a universal good way to do this.
0 Kudos
Highlighted

Re: XPath and Installscript...

I'm sure it's possible, but at that level of complexity, is it best to put it in the installer at all? Some people believe in configuration data is a pain and belongs in the application not the installer.
0 Kudos
Highlighted
Pilgrim

Re: XPath and Installscript...

Your preaching to the choir Chris. Preaching to the choir. 🙂
0 Kudos
Highlighted

Re: XPath and Installscript...

I'm in the middle of the road on this one. If an application only has one or two pieces of critical configuration then I'll probably do it in the installer. Things like I just installed a database and now I need to tweak a web.config connection string to point to it or I just created a service account and now I need to set the app_pool or windows service to use it.

But if something asks for dozens of settings I'll usually kick back and tell dev that it's unsustainable. I usually show them two installs as an example:

SQL Server - boat loads of custom UI and windows workflow to get a bunch of settings and do all the config during the installer

Team Foundation Server - a simple installer that lays everything down and then gives you a configuration utility to configure the different roles ( app tier, build controller, proxy ) in the different ways with a command line and config file to drive it all.

All in all, I like the TFS route the best.
0 Kudos