« Previous Next »

Thread: Problems with xmlns and Powershell

Last post 08-26-2009 1:15 PM by anilr. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 08-25-2009, 5:52 PM

    • deuxex25
    • Not Ranked
    • Joined on 02-16-2005, 12:56 PM
    • Posts 3

    Problems with xmlns and Powershell

    I am trying to use powershell to update xml nodes in my web.config.

    If the configuration element looks like below with xmlns it does not work
    configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"

    If I remove the xmlns attribute, then it works fine. I would rather not have to remove that attribute from all of our web.config files.

    I want to be able to pass in parameters to the Powershell script, so I wrote it this way.

    Param($config_path,$node,$new_value)
    # Get the content of the config file and cast it to XML
    $xml = [xml](get-content $config_path)
    #get node and set the new value for configSource
    #//client[@configSource] sample node
    $xml.SelectSingleNode("$node").configSource = $new_value
    # Save it
    $xml.Save($config_path)

    Is there any possible way I can use Powershell to do the same thing without having to remove the xmlns attribute. Here's an article about why SelectSingleNode does not work with xmlns, but I do not know how I can do what I need with Powershell.

    http://devio.wordpress.com/2008/07/22/xmlns-selectnodes-empty-xmlnodelist/

     

    Howard
  • 08-26-2009, 9:02 AM In reply to

    • deuxex25
    • Not Ranked
    • Joined on 02-16-2005, 12:56 PM
    • Posts 3

    Re: Problems with xmlns and Powershell

  • 08-26-2009, 1:15 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Problems with xmlns and Powershell

    Also, I would suggest using IIS configuration APIs (try out the IIS powershell provider) to edit the configuration rather than using xml APIs - editing the config using xml APIs may get you a web.config file which is valid xml but not valid config since the config system enforces extra restrictions on the file.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
Page 1 of 1 (3 items)
Microsoft Communities