System.Xml
PowerShell primarily uses the System.Xml.XmlDocument
type to work with XML content. This type is part of the System.Xml
namespace. The documentation for the types available in this namespace is available on Microsoft Docs: https://docs.microsoft.com/dotnet/api/system.xml.
The System.Xml.XmlDocument
type is normally used via a type accelerator.
The XML type accelerator
The XML type accelerator ([Xml]
) can be used to create instances of XmlDocument
, as shown in the following code:
[Xml]$xml = @"
<?xml version="1.0"?>
<cars>
<car type="Saloon">
<colour>Green</colour>
<doors>4</doors>
<transmission>Automatic</transmission>
<engine>
<size>2.0</size>
<cylinders>4</cylinders>
</engine>
</car>
</cars>
"@
Elements and attributes of an XmlDocument...