I am having trouble replacing an attribute in an XML file while saving spaces.
Attempt 1
$xml = [xml](get-content data.xml) $xml.Path.To.Attribute = $value set-content data.xml [String]$value
Result: Exceptional spaces (namely newlines) are removed
Attempt 2
$xml = new-object xml $xml.PreserveWhitespace = true $xml.PreserveWhitespace
Result: PreserveWhitespace remains false
Attempt 3
$xml = get-content data.xml $xml = [regex]::replace($xml, "pattern", "replacement") set-content data.xml $xml
Result: [regex]::replace puts the end of the line
Am I taking crazy pills with me?
powershell
Richard Szalay
source share