Appending to/Removing empty xml nodes using powershell

Susan

New Member
PowerShell/xml beginner here....I'm trying to append to or remove empty xml nodes using PowerShell as part of a Nuget Package. The xml file has the following format...\[code\]<Root> <service name="first"> <item> </item> </service> <service name ="second"> <item> </item> </service></Root>\[/code\]First my script select one of the services and save it as a variable, say if the user wants to select service 1.....\[code\]if ($xml.Root.service.name -eq $serviceName){ $myService = $xml.Root.service}\[/code\]Problem is later on, I need to append elements to the node/delete the node...I have something like\[code\] $newNode = $xml.CreateElement('new'... ......... $empty = $myService.SelectSingleNode('./item') $empty.PrependChild($newNode)\[/code\]But I can't get the this method to work.Any suggestions would be appreciated...
 
Back
Top