February 2019
Intermediate to advanced
626 pages
15h 51m
English
If an XML document includes a namespace, then queries for elements within the document are more difficult. Not only must the namespace tag be included, but XmlNamespaceManager must be defined.
Select-Xml builds a namespace manager based on the content of a hashtable when the Namespace parameter is used:
[Xml]$xml = @"
<?xml version="1.0"?>
<cars xmlns:c="http://example/cars">
<car type="Saloon">
<c:colour>Green</c:colour>
<c:doors>4</c:doors>
<c:transmission>Automatic</c:transmission>
<c:engine>
<size>2.0</size>
<cylinders>4</cylinders>
</c:engine>
</car>
</cars>
"@
Select-Xml '//car/c:engine' -Namespace @{c='http://example/cars'} -Xml $xml
If the SelectNodes method is being used, XmlNamespaceManager must be built ...
Read now
Unlock full access