Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. AppendChild problem

AppendChild problem

Scheduled Pinned Locked Moved XML / XSL
htmlxmlhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    I'm attempting to modify an XML Document using System.Xml's DOM methods. I'm loading a template document, then modifying it with values from my application. The final document has some repeating nodes, where the template document includes only one template node for these. I use the following technique to create the required nodes: XmlNode node = requestedMessagesElement.SelectSingleNode( "//Message"); XmlElement firstMessageElement = (XmlElement)node; // Add message nodes for each message for (long i = 0; i < numMessages; ++i) { XmlElement messageElement; // For first element, modify existing message if (i == 0) messageElement = firstMessageElement; // For successive elements, copy existing element to modify else { messageElement = (XmlElement)firstMessageElement.Clone(); messageElement = (XmlElement)requestedMessagesElement.AppendChild( messageElement); } // Other modifications here } For some reason, when I execute the code, the resulting XML misplaces the resulting nodes. For example, if the nodes are appended in order "1, 2, 3", I'm consistently getting results in order "3, 1, 2". Any suggestions greatly appreciated. PS. I use the value returned from "AppendChild" as the documentation states that the method returns the appended node - just covering tracks in case the system decides to insert a copy of the passed node for some reason.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups