February 2019
Intermediate to advanced
626 pages
15h 51m
English
PowerShell can be used to create XML documents from scratch. One possible way to do this is by using the XmlWriter class:
$writer = [System.Xml.XmlWriter]::Create("$pwd\newfile.xml")
$writer.WriteStartDocument()
$writer.WriteStartElement('cars')
$writer.WriteStartElement('car')
$writer.WriteAttributeString('type', 'Saloon')
$writer.WriteElementString('colour', 'Green')
$writer.WriteEndElement()
$writer.WriteEndElement()
$writer.Flush()
$writer.Close()
Elements opened by WriteStartElement must be closed to maintain a consistent document.
The XmlWriter class is a buffered writer. The Flush method is called at the end to push the content of the buffer back to the file.
The format of generated XML can be changed by supplying ...
Read now
Unlock full access