I've got an XML file that's something like this:
<globalConfigs>
<!-- some settings -->
<globalConfig key="currency" value="£" />
</globalConfigs>
And I've got some Powershell which is manipulating it along the lines of this:
function Update-Config ($filePath, $siteName) {
[xml]$config = Get-Content $filePath;
$newNode = $config.CreateElement("globalConfig");
$keyAttribute = $config.CreateAttribute("key");
$keyAttribute.Value = "currencyCode";
$newNode.Attributes.Append($keyAttribute);
$valAttribute = $config.CreateAttribute("value");
$valAttribute.Value = "GBP";
$newNode.Attributes.Append($valAttribute);
$config.globalConfigs.AppendChild($newNode);
Write-Log "Added config node to site.";
$config.Save($filePath);
}
Now this works as expected in that it adds the new key. But the resulting xml adds an extra character in before the pound sign:
<globalConfigs>
<!-- some settings -->
<globalConfig key="currency" value="£" />
<globalConfig key="currencyCode" value="GBP" />
</globalConfigs>
What is causing this extra character? It appears to be intermittent, but it's added more often than not.