none
Best way to move children RRS feed

  • Question

  • Hi all;

    I need to move child nodes from a SdtBlock to a SdtRun (except the SdtContentBlock which I've removed). At present I do:

    foreach (var elemOn in sdtOn.ChildElements)
    	sdtRun.AppendChild(elemOn.CloneNode(true));
    

    But that seems expensive to me as the sdtOn is going to be discarded and has been removed already from the document. Is there a way to move the elements over?

    thanks - dave


    The future of B.I. - Raw & Uncut
    Friday, May 27, 2011 2:19 PM

Answers

  • You can remove the elements from the original parent and then add them to the new one which avoids the cloning of the moved element:

    while(stdOn.ChildElements.Count != 0)
    {
      var moveElement = stdOn.ChildElements[0];
      moveElement.Remove();
      stdRun.Append(moveElement);
    }
    
    

     

     Eric

     

    • Proposed as answer by EWoodruff Friday, May 27, 2011 3:02 PM
    • Marked as answer by DavidThi808 Friday, May 27, 2011 3:18 PM
    Friday, May 27, 2011 3:01 PM

All replies