How to edit 1 line in a XML Config File?

(imported topic written by fhack)

I have a file called user.config, basically it’s an XML Configuration File.

I have 4 configurations that change only one part: “CHANGE_HERE” down in the code. I’m trying to figure out how I can open the file and change that 1 line.

For each action I would include the code to change that one line so I can lay down a default file and change the line. The file gets copied over to each user’s profile but I have a Perl Script that does that. So I just have to modify the user.config file before running the Perl Script.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
    <sectionGroup name="userSettings">
        <section name="QTSDataAccess.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<userSettings>
    <QTSDataAccess.My.MySettings>
        <setting name="SQLDBName" serializeAs="String">
            <value>CHANGE_HERE</value>
        </setting>
    </QTSDataAccess.My.MySettings>
</userSettings>
</configuration>

(imported comment written by fhack)

The solution I thought I had didn’t work.

(imported comment written by fhack)

Okay I’m using this code:

parameter 
"baseFolder" =  
"{pathname of windows folder}\MSI\QTS_7.3.46\" parameter 
"filename" = 
"{parameter "baseFolder
"}Roaming\user.config"   parameter 
"textToReplace" = 
"<value></value>" parameter 
"newText" = 
"<value>QTS_Test</value>" appendfile 
{concatenation 
"%0d%0a" of ( 

if (it contains (parameter 
"textToReplace")) then ((preceding text of first (parameter 
"textToReplace") of it) & (parameter 
"newText") & (following text of first (parameter 
"textToReplace") of it) ) 

else it ) of lines of file (parameter 
"filename")
}

But when I run it in the Fixlet Debugger or the Action from the TEM console it doesn’t do it. It reports it did but the file isn’t changed.

This is the output from the Fixlet Debugger:

"STATUS: Running action…

Command succeeded parameter “baseFolder” = “C:\Windows\MSI\QTS_7.3.46”

Command succeeded parameter “filename” = “C:\Windows\MSI\QTS_7.3.46\Roaming\user.config”

Command succeeded parameter “textToReplace” = “”

Command succeeded parameter “newText” = “QTS_Test”

Command succeeded appendfile {concatenation “%0d%0a” of ( if (it contains (parameter “textToReplace”)) then ((preceding text of first (parameter “textToReplace”) of it) & (parameter “newText”) & (following text of first (parameter “textToReplace”) of it) ) else it ) of lines of file (parameter “filename”)}

Command succeeded (file created) appendfile <?xml version="1.0" encoding="utf-8"?>

<QTSDataAccess.My.MySettings>

QTS_Lonestar

</QTSDataAccess.My.MySettings>

Command succeeded appendfile <?xml version="1.0" encoding="utf-8"?>

<QTSDataAccess.My.MySettings>

QTS_Test

</QTSDataAccess.My.MySettings>

  • Result —

Evaluation completed successfully!"

(imported comment written by SystemAdmin)

To my knowledge there is no easy way to do this directly in TEM action, instead I use a VBScript to edit XML.

(imported comment written by SystemAdmin)

Here is an example:

// Set default Server IP address:

delete __createfile

// Using ActionScript, this will create a new VBScript file, write to it, execute it with cscript, and delete it.

// Begin reading lines and write to the VBScript file.

createfile until END_OF_FILE

'Begin VBScript Code

Set xmlDoc = _

CreateObject(“Microsoft.XMLDOM”)

xmlDoc.Async = “False”

xmlDoc.Load("{value “InstallLocation” of key whose (value “DisplayName” of it as string contains “Polycom CMA Desktop” AND (it >= “5.2.2.13044” as version) of (value “DisplayVersion” of it as string as version)) of key “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of x32 registry}assets\config\configuration.xml")

Set colNodes=xmlDoc.selectNodes ("/Varies/specCmaServerIpAddress")

'Set Default CMA Server IP address

For Each objNode in colNodes

objNode.Text = “0.0.0.0”

Next

Set colNodes=xmlDoc.selectNodes ("/Varies/cmaServerType")

'Change CMA Server Type to “Specify” instead of “Automatic” so manual IP address settings work (from above)

For Each objNode in colNodes

objNode.Text = “specify”

Next

Set colNodes=xmlDoc.selectNodes ("/Varies/signinAutoStart")

'Disable CMA Desktop from starting with Windows

For Each objNode in colNodes

objNode.Text = “disable”

Next

xmlDoc.Save “{value “InstallLocation” of key whose (value “DisplayName” of it as string contains “Polycom CMA Desktop” AND (it >= “5.2.2.13044” as version) of (value “DisplayVersion” of it as string as version)) of key “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of x32 registry}assets\config\configuration.xml”

END_OF_FILE

// Copy the newly created file to a filename that has a .vbs extension.

delete EditXML.vbs

copy __createfile EditXML.vbs

waithidden cscript.exe EditXML.vbs

delete EditXML.vbs