Powershell: XPath cannot select when element has "xmlns" tag? Powershell: XPath cannot select when element has "xmlns" tag? powershell powershell

Powershell: XPath cannot select when element has "xmlns" tag?


What you added is default namespace. Unlike prefixed namespace, descendant elements inherit ancestor default namespace implicitly, unless otherwise specified (using explicit prefix or local default namespace that points to different URI).

To select element in namespace, you'll need to define prefix that point to the namespace URI and use that prefix properly in your XPath, for example :

$ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)$ns.AddNamespace("d", $xml.DocumentElement.NamespaceURI)$xml.SelectNodes("//d:Folder", $ns)