我在PowerShell脚本中有一个XML代码。代码执行得很好,我在正确的myTest.xml
输出文件中得到了XML结构。我需要将这个myTest.xml
输出文件转换为具有output.trg文件中相同XML结构的.trg
(例如output.trg
)文件。如何做到这一点?
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$XmlWriter = [System.XML.XmlWriter]::Create("C:\myTest.xml", $xmlsettings)
$xmlWriter.WriteStartDocument()
$xmlWriter.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='style.xsl'")
$xmlWriter.WriteStartElement("Root")
$xmlWriter.WriteElementString("Test1","1")
$xmlWriter.WriteElementString("Test2","2")
$xmlWriter.WriteElementString("Test3","3")
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
预期的输出文件(output.trg
):
<Root>
<Test1>1</Test1>
<Test2>2</Test2>
<Test3>3</Test3>
</Root>