Parsing XML with PowerShell

This script allows to parse an XML file.

In this example, the XML must be named config.xml and must be located in the same folder as the script.

The variable $PSScriptRoot is used to retrieve the path where the script is launched.

 

1. Parsing XML – Single Tags and recursively

Let’s create an XML file named “config.xml” in the same location as the script with the following content:

 

The following script allows to parse the XML:

 

2. Parsing XML – Looping a Loop

The goal here is to retrieve data of a loop inside another loop.

Let’s create an XML file named “config.xml” with the following content:

 

The following script allows to parse the XML, retrieving dynamically the data using 2 loops.