Better way to iterate XML and update in powershell? -


i got work, not happy result, , wondering how can done better.

xml

<?xml version="1.0" encoding="utf-8"?> <configuration version="3">   <library>     <default-theme>none</default-theme>      <export-path>default</export-path>     <caching-enabled>true</caching-enabled>   </library> </configuration> 

ps

function modifyconfigfile() {   $xml = new-object -typename xml   $xml.load($filepath)   $item = $xml.configuration.library    $item.childnodes.item(1)."#text" = "modify-test"   $xml.save($newfilepath) } 

i trying update "export-path" text node, code does do, code dependent on me knowing node 2nd item in child node of parent library.

is there cleaner way?

or @ least way me verify updating node want "export-path"?

here's more 'powershell' approach loading file, , incorporating petseral comment

[xml]$doc = gc $filepath $doc.configuration.library.'export-path' = "modify-test" $doc.save($filepath) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -