Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

xml save indentation lost

$
0
0

Hello,

I'm trying to save some XML but I keep loosing the formatting.  One note before I continue.  This code works fine on a server in the US but misbehaves on a server in Brazil.  When I save the file on the US server everything is formatted as expected with indentation.  When I run the same code on the Brazil server it saves everything on one single line.  I've set all the OS "Region and Language" features that I can find to match that of the US server.

Any help would be greatly appreciated.

Sample XML:

<?xml version="1.0" encoding="utf-8"?>
<Profiles>
 <Profile>
  <userName>floresb</userName>
  <Access>Administrator</Access>
 </Profile>
 <Profile>
  <userName>mcquillj</userName>
  <Access>Operator</Access>
 </Profile>
</Profiles>

Sample Code:

 

 

 

 

$xmlFile = "c:\temp\Test.xml"

[xml]$myXML = Get-Content($xmlFile)

foreach ($node in $myXML.Profiles.Profile)
{
 $node.Access = "Operator"
 $myXML.Save($xmlFile)
}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles