Append XMl node

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Robin16 Robin16 3 years, 9 months ago.

  • Author
    Posts
  • #8309
    Profile photo of Robin16
    Robin16
    Participant

    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..

    false

    true

    false

    DATABASE_RESTORE

    STATE_RECOVER

    false

    false

    false

    false

    false

    false

    false

    false

    false

    Informatica_Test11

    Informatica_Test11

    (GMT-05:00) Eastern Time (US & Canada)

    false

     

    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

  • #8340
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8346
    Profile photo of Robin16
    Robin16
    Participant

    Thanks Don...

You must be logged in to reply to this topic.