Here's a PowerShell script to do it. It takes the following input:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<ChildNode value1="5" value2="6" value3="happy" />
</Node>
...and produces this as output:
<?xml version="1.0" encoding="utf-8"?>
<Node>
<ChildNode
value1="5"
value2="6"
value3="happy" />
</Node>
Here you go:
param(
[string] $inputFile = $(throw "Please enter an input file name"),
[string] $outputFile = $(throw "Please supply an output file name")
)
$data = [xml](Get-Content $inputFile)
$xws = new-object System.Xml.XmlWriterSettings
$xws.Indent = $true
$xws.IndentChars = " "
$xws.NewLineOnAttributes = $true
$data.Save([Xml.XmlWriter]::Create($outputFile, $xws))
Take that script, save it as C:formatxml.ps1. Then, from a PowerShell prompt type the following:
C:formatxml.ps1 C:PathToUglyFile.xml C:PathToNeatAndTidyFile.xml
This script is basically just using the .NET framework so you could very easily migrate this into a C# application.
NOTE: If you have not run scripts from PowerShell before, you will have to execute the following command at an elevated PowerShell prompt before you will be able to execute the script:
Set-ExecutionPolicy RemoteSigned
You only have to do this one time though.
I hope that's useful to you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…