[ACCEPTED]-Using PowerShell, how do I add multiple namespaces (one of which is the default namespace)?-namespaces

Accepted answer
Score: 20

PowerShell v2 makes this simpler:

$ns = @{

$xml | Select-Xml '//dns:image/@xlink:href' -Namespace $ns

If you 1 want to do it the other way try:

$nsmgr = New-Object System.Xml.XmlNamespaceManager $xml.NameTable

$root = $xml.DocumentElement
$nodelist = $root.SelectNodes("//dns:image/@xlink:href", $nsmgr)

foreach ($xmlnode in $nodelist)
Score: 0

Figured it out. Had to use $null for the 3 prefix of the default namespace ($null is 2 equivalent to String.Empty in C#).

Working 1 code:

    [System.Xml.XmlNamespaceManager] $nsmgr = $xml.NameTable;

    [System.Xml.XmlNodeList] $nodelist;
    [System.Xml.XmlElement] $root = $xml.DocumentElement;
    $nodelist = $root.SelectNodes("//image/@xlink:href", $nsmgr);

    Foreach ($xmlnode in $nodelist)

More Related questions