How do I access an element with xpath with a namespace in powershell? How do I access an element with xpath with a namespace in powershell? powershell powershell

How do I access an element with xpath with a namespace in powershell?


You've got a few problems going on. First you need to specify the namespace in the XPath pattern, the XML isn't well formed (closing tag is not an end tag) and Select-Xml returns XmlInfo and not XmlElement directly. Try this:

$xml = [xml]@'<submission version="2.0" type="TREE" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:noNamespaceSchemaLocation="TREE.xsd" xmlns="some/kind/of/tree/v1">  <group>    <item></item>    <item></item>    <item></item>  </group></submission>'@$ns = @{dns="some/kind/of/tree/v1"}$items = Select-Xml -Xml $xml -XPath '//dns:item' -Namespace $ns$items | Foreach {$_.Node.Name}