Multiple namespaces problem with xpath and powershell RRS feed

  • Question

  • I have a similar xml like this: 

    <?xml version="1.0"?>
    <Books xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/AurumServicesConfig.xsd">

    and my query in the script looks like this: 

    [xml]$BookConfig = Get-Content $bookConfigLocation

      $nsm = New-Object Xml.XmlNamespaceManager($bookConfig.NameTable)
      $nsm.AddNamespace('ns', $bookConfig.DocumentElement.NamespaceURI)

    I am trying to get the enabled element with the book named: Peace.And.Religion : 

    $bookvalue2 = $bookConfig.SelectSingleNode('//ns:Books/Book[Name = "Peace.And.Religion"]/Enabled', $nsm)

    I am getting the value = $null.

    Where am I failing with my query? 

    • Moved by Bill_Stewart Wednesday, November 29, 2017 6:33 PM Abandoned
    Thursday, October 12, 2017 6:52 AM

All replies

  • Try this:



    Thursday, October 12, 2017 7:07 AM
  • Thanks! 

    Its working now! 

    Thursday, October 12, 2017 7:19 AM