Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell weirdly encodes ampersands when I try to set the value to an xml attribute

In my build script, I have a helper powershell function as below:

function set-connectionstring {
  param($path, $name, $value)
  $settings = [xml](get-content $path)
  $setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
  $setting.connectionString = "$value"
  $setting.providerName = "System.Data.SqlClient"
  $resolvedPath = resolve-path($path) 
  $settings.save($resolvedPath)
}

It works great except that when I try to set the value, it encodes ampersands weirdly. Here is the issue:

Inside my connection string I have &quot value. This should be perfectly valid. However, my above code transforms this into " which is totally unreasonable. Do you have any idea I can solve this problem?

like image 757
tugberk Avatar asked Jul 23 '12 11:07

tugberk


1 Answers

Have you try to decode your connection string first? Here is sample:

[System.Reflection.Assembly]::LoadWithPartialName("System.web")
[System.Web.HttpUtility]::HtmlDecode(""")
like image 94
Akim Avatar answered Nov 15 '22 04:11

Akim