Reader small image

You're reading from  Mastering PowerShell Scripting - Fourth Edition

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781800206540
Edition4th Edition
Right arrow
Author (1)
Chris Dent
Chris Dent
author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent

Right arrow

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 = @" 
<...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerShell Scripting - Fourth Edition
Published in: Jun 2021Publisher: PacktISBN-13: 9781800206540

Author (1)

author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent