Append XMl node

Hi,

i’m trying to create a node and append it to the existing xml file using below powershell code.

[xml]$temp = Get-Content C:\temp\test.xml

$device = $temp.CreateElement(“device”)

$device.InnerXml = “$dev”

$temp.TMMsg_CreateTaskReq.taskinfo.subTasks.options.restoreOptions.sqlServerRstOption.Appendchild($device)

$temp.Save(“C:\temp\test.xml”)

Here “$dev” has all the values to append in to xml file
part of xml file…where i would like to append the node…

<sqlServerRstOption>

<dbOnly>false</dbOnly>

<overWrite>true</overWrite>

<pointOfTimeRst>false</pointOfTimeRst>

<sqlRestoreType>DATABASE_RESTORE</sqlRestoreType>

<sqlRecoverType>STATE_RECOVER</sqlRecoverType>

<stopStartSSA>false</stopStartSSA>

<preserveReplicationSettings>false</preserveReplicationSettings>

<stopMarkRestore>false</stopMarkRestore>

<stopBeforeMarkRestore>false</stopBeforeMarkRestore>

<partialRestore>false</partialRestore>

<logShippingOnly>false</logShippingOnly>

<ffgRestore>false</ffgRestore>

<ignoreFullBackup>false</ignoreFullBackup>

<vSSBackup>false</vSSBackup>

<restoreSource>Informatica_Test11</restoreSource>

<database>Informatica_Test11</database>

<timeZone>

<TimeZoneName>(GMT-05:00) Eastern Time (US & Canada)</TimeZoneName>

</timeZone>

<keepDataCapture>false</keepDataCapture>

</sqlServerRstOption>

 

In the above xml code, new node “Device” is saving above sqlServerRstOption, but it should be between vSSBackup and restoreSource nodes.
Is there any way we could do that ?
Please let me know your suggestions…
Thanks in advance

File attachments need to be .TXT filenames.

XML isn’t sensitive to order or sequence in the way you’re asking. The XML code in .NET isn’t worried so much how the XML looks to a human being, it worries about it being machine-readable. The machine doesn’t care what order nodes come in, so there’s no provision for inserting a node in a particular spot with regard to its siblings at the same level.

In other words, as far as the computer’s concerned, where it’s putting the new node is fine. It’s like in a SQL Server database. The physical order of the rows as they’re stored on disk doesn’t really matter, and you don’t really have control over it when you insert new rows.

Thanks Don…