Examples/Example04.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases', '')]
param()

Import-Module -Name XmlEx -Force;

$x = XmlDocument {
    XmlDeclaration -Encoding 'utf-8' -Standalone 'yes'
    XmlElement 'rootElement'
}

## Appending an XmlElement to an exising root XmlElement. This is required because
## $x.rootElement is coerced into [System.String] (only applicable to the root node)?
XmlElement -XmlElement $x.SelectSingleNode('/rootElement') -Name 'subElement' {
    XmlElement 'TextNode' {
        XmlText 'My text node'
    }
} -Verbose

$x | Format-XmlEx