I have simple xml file wherein when just use the get-content and save the xml file back. Its corrupting the xml file and getting unusable. Your help/suggestion/solutions are most welcome.
$xmlfile = 'C:\Test\stack.xml'
[xml]$xmlcontent = (Get-Content $xmlfile)
$xmlcontent.Save($xmlfile)
Below is my sample xml file which im using here in my case to run my powershell script mentioned above. You could save the below xml in to file for refernce.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fccconfig SYSTEM "fccconfig.dtd">
<fccconfig version="1.2.3">
<fccdefaults>
<!-- general -->
<property name="FCC_CacheLocation" value="C:/Users/Public/sometestCache" overridable="true"/>
<property name="FCC_LogFile" value="C:/Users/Public/sometestfile.log" overridable="true" />
<!-- external site access definition -->
<!-- <site id="013B998A65427E" overridable="true"> -->
<!-- <parentfsc address="localhost:4567" priority="0"/> -->
<!-- <parentfsc address="myserverhost:4444" priority="1"/> -->
<!-- <assignment mode="parentfsc" /> -->
<!-- </site> -->
<site id="-987654321" overridable="true">
<parentfsc address="http://testlink:12345/" priority="0" />
</site>
<!--__ANT_MARK__-->
</fccdefaults>
<!-- default parentfsc - this is a marker that will be overwritten by the installer -->
<parentfsc address="address1.com:2020" priority="0" transport="lan"/>
<parentfsc address="address1.com:2020" priority="1" transport="lan"/>
</fccconfig>
In the 2nd of the xml after Running the Script and unknown chracters are getting added [] . And also the spacing between the xml file's gets changed. Below is snippet of the difference in files.