试图格式化我的xml文件,但我无法找到如何设置powershell来完成此操作。所有引用C++或C#的内容:(
这就是我想要的样子:
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />但情况是这样的:
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" />是吗?我在powershell中尝试过不同的方法,我无法让它添加空间。下面是看起来最有希望的地方,但没有效果。
$settings = New-Object system.Xml.XmlWriterSettings
$settings.OmitXmlDeclaration = $false
$settings.NewLineOnAttributes = $true
$XmlWriter = New-Object System.Xml.XmlTextWriter($path,$null)
$xmlWriter.Formatting = 'Indented'
$xmlWriter.Indentation = 1
$XmlWriter.IndentChar = "`t"感谢任何有想法的人!!
发布于 2014-04-25 19:46:43
也许这在powershell中是不可能的(没有实际的加载C#码)
以下代码返回一个错误:
$settings = New-Object system.Xml.XmlWriterSettings;
$settings.Indent = $true;
$settings.OmitXmlDeclaration = $true;
$settings.NewLineOnAttributes = $true;
$path = 'c:\test\meh.xml'
Add-Type -AssemblyName 'System.Xml'
$writerClass = New-Object XML.XmlTextWriter $path, ([Text.Encoding]::Unicode)
$writer = New-Object ([System.Xml.XmlWriter]::Create($writerClass,$settings))
New-Object : Cannot find type [System.Xml.XmlCharCheckingWriter]: verify that the assembly containing this type is loaded.XmlCharCheckingWriter是一个内部类可能是造成这个问题的原因?我不知道你怎么用powershell来完成这个任务。
https://stackoverflow.com/questions/23300408
复制相似问题