cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JimmiLee
Level 6

XML Editing . . .

I'm using a Basic MSI Project.
I have a web.config whereing I need to put some paths, defined during run time by the user.
The problem is that the built in XML editor can't do the job, as each of the paths I need to change are between a pair ov value tags like this:
URL to be changed

If I load the xml file into the editor and tell it to change the value attribute, it basically changes it to:
URL to be changed

So it simply adds a value with the new URL inside the first tag . . .
I'm thinking I could read in the text from the xml file somehow, alter it and then write it back - basically doing some sort of text editing in an install script, but I'm not sure how, so if anyone can pinpoint me to a solution, feel fere to do so 🙂
Labels (1)
0 Kudos
(5) Replies
EJSchuiteman
Level 4

Easiest way i think of is creating a VBscript custom action and load & edit here the xml file. This is how we do it.

You have to change "value(s)" to your own names and values.

Example:
[SIZE="2"]Dim xmlDoc : Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(Session.Property("INSTALLDIR") & "Web.Config") Then
Dim objFile : Set objFile = objFSO.GetFile(Session.Property("INSTALLDIR") & "Web.Config")
Dim nFileAttributes : nFileAttributes = objFile.Attributes
If nFileAttributes And 1 Then
objFile.Attributes = objFile.Attributes - 1
End If

xmlDoc.async = False
xmlDoc.load(Session.Property("INSTALLDIR") & "Web.Config")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
MsgBox("Error " & myErr.reason)
Else
xmlDoc.selectSingleNode("//value/value[@key=""value""]").setAttribute "value", "value"

xmlDoc.Save(Session.Property("INSTALLDIR") & "Web.Config")
End If

objFile.Attributes = nFileAttributes
Set objFile = Nothing
End If

Set xmlDoc = Nothing
Set objFSO = Nothing[/SIZE]
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

The InstallShield XML Changes view way of doing this, so long as it's writing a known value, is to use the Advanced tab of your element to "Set element content". Sorry I missed your question first time around.
0 Kudos
JimmiLee
Level 6

Thanx mate, that worked - setting them under the advanced tab that is . . .
However, one of the settings has to be set to [TARGETDIR]Organization.config
This works, except that instead of the actual target dir it just sets it to C:\Organization.config so I figure the target dir, at the time when the XML thingie runs, contains a wrong argument . . .
Looks like I'll have to make an installscript that sets a different global (TARGETDIR2) or whatever, after the user has defined this dir . . .

Or ? ? ?
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

I think you might want [INSTALLDIR] instead of [TARGETDIR]. Have you tried that yet?
0 Kudos
JimmiLee
Level 6

That did it - INSTALLDIR and not TARGETDIR . . .

Thanx mate 🙂
0 Kudos