如何使用 Powershell 将 XML 正确导出到文件 [英] How to properly export XML to file using Powershell
问题描述
使用 [XML]$Var = Get-Content -Path $PathToAnyValidXML
导入任何有效的 XML 文件作为源我无法正确导出其内容.
Importing any valid XML file as source using [XML]$Var = Get-Content -Path $PathToAnyValidXML
I am unable to export it's content properly.
使用 Set-Content SomePath $Var
,文件以 System.Xml.XmlDocument 作为内容结束.
Using Set-Content SomePath $Var
, the file ends with System.Xml.XmlDocument as content.
使用 $Var |Export-Clixml SomePath
,文件以 XML 中的原始 XML 结尾
Using $Var | Export-Clixml SomePath
, the file ends with the original XML inside an XML
将原始 XML 正确写入文件的正确方法是什么?(在将 $PathToAnyValidXML 导入到 Powershell 上的变量后,获取与 $PathToAnyValidXML 上完全相同的内容)
What is a correct method to write raw XML to a file properly ? (Get the exact same content that was on $PathToAnyValidXML once it was imported to a variable on Powershell)
如果我们需要使用 XPath 或 Objects,请尽可能提供两种方法的示例.
If we need to use XPath or Objects, provide example with both method if possible.
推荐答案
由于您使用 [XML] 将文件作为 XML 对象导入,要以这种方式导出它,您应该使用 Save()
数学.
Since you imported the file as an XML Object using [XML], to export it that way you should use the Save()
Mathod.
$VAR.save("c:\works.xml")
希望能帮到你
这篇关于如何使用 Powershell 将 XML 正确导出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!