The XDocument class is used to load or parse a document. XML content may be cast to an XDocument in the same way that content is cast using the [Xml] type accelerator:
using assembly System.Xml.Linq [System.Xml.Linq.XDocument]$xDocument = @" <?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> "@ $xDocument.Save("$pwdcars.xml")
If the content has been saved to a file, the Load method may be used with a file name:
$xDocument = [System.Xml.Linq.XDocument]::Load("$pwdcars.xml")