System.Xml.Linq
The System.Xml.Linq
namespace was added with .NET 3.5. This is known as LINQ to XML. Language Integrated Query (LINQ) is used to describe a query in the same language as the rest of a program. Therefore, interacting with a complex XML document does not require the use of XPath
queries.
System.Xml.Linq
is loaded by default in PowerShell 7. Windows PowerShell can make use of System.Xml.Linq
once the required assembly has been added:
Add-Type -AssemblyName System.Xml.Linq
This can also be phrased as follows:
using assembly System.Xml.Linq
As a newer interface, System.Xml.Linq
tends to be more consistent. The same syntax is used to create a document from scratch that is used to add elements and so on.
Opening documents
The XDocument
class is used to load or parse a document. XML content may be cast to XDocument
in the same way that content is cast using the [Xml]
type accelerator:
[System.Xml.Linq.XDocument]$xDocument = @"
<...