i'm getting crazy. I need to modify this XML file in powershell
<system.diagnostics><trace autoflush="attr1" indentsize="attr2"><listeners><add name="attr1" type="attr2" initializeData="attr3" /><remove name="Default" /></listeners></trace><switches><add name="attr1" value="attr2" /> </switches></system.diagnostics>
i need to add a new element after the "remove" one: i tried to use the following code
$fileXML = 'C:\Users\XXXX\file.config'$contentXML = New-Object XML$contentXML.Load($fileXML)$elementXML = $contentXML.SelectSingleNode("//listeners")$childElementsXML = $contentXML.CreateElement("set")$elementXML.AppendChild($childElementsXML)$contentXML.DocumentElement.AppendChild($elementXML)$contentXML.Save($fileXML)
but it's moving the element "listeners" at the same level of "trace". What am i doing wrong?
<system.diagnostics><trace autoflush="attr1" indentsize="attr2"></trace><switches><add name="attr1" value="attr2" /></switches><listeners><add name="attr1" type="attr2" initializeData="attr3" /><remove name="Default" /><set /></listeners></system.diagnostics>
thanks in advance for your help guys