1

Following is the powershell code which I am using to remove parent node from the web.config file:

 $c = "C:\test\web.config"
     $xml = ( Get-Content $c)
     $ConnectionString = $xml.configuration.appSettings.add | Where-Object {$_.Key -eq 'ConnectionString'}
     $xml.configuration.RemoveChild($ConnectionString.ParentNode)
     $xml.save($c)

After removing <appSettings> tag from web.config file. Some special Characters like &#xA; are adding to web.config file as below:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, &#xA;        System.Web.Extensions, Version=3.5.0.0, Culture=neutral, &#xA;        PublicKeyToken=31bf3856ad364e35">
   </configSections>
</configuration>

Please let me know how to save xml file without special characters like &#xA; and new line

1 Answer 1

1

Just had this issue, I filtered all non ascii-256 chars with this regex

$myText = # your text here
$cleanText = ($myText -replace"[^\x00-\xFF]","");

Are you sure this chars should be removed? You can also try to change encoding with something like this

$myText | Out-File -FilePath "yourPath" -Encoding utf8
Sign up to request clarification or add additional context in comments.

1 Comment

I have used both [^\x00-\xFF] and utf8 encoding for xml file still same special characters i.e, &#xD;&#xA; and &#xA; are coming instead of white spaces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.