Question

Trying to format my xml file and I can't find out how to setup powershell to do this. Everything references C++ or C# :(

This is how I want it to look:

    <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" />

But this is how it looks:

        <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" />

Yuk right? I have tried different ways in powershell, I cannot get it to add the space. Below is what looked to be the most promising, but it has no effect.

$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"

Thanks for anybody who has an Idea !!

Was it helpful?

Solution

Maybe this isn't possible in powershell (without actually loading C# code)

The following code returns an error:

$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 is an internal class which may be the cause of the problem?. I'm not sure how you would make this work with powershell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top