tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Moving Elements Up and Down

Open ghost opened this issue 10 years ago • 3 comments

Hi, I am not entirely sure the best way to move an Element up one, or down one. It would be very convenient to have a specific function to copy the entire contents of an Element (all attributes, and text) and then to move it to any place within the current Document. I looked at #135, but this seems to be addressing moving to a new document.

This would be useful for copying items, i.e. myXMLElement=myBaseXMLElement->FirstChildElement("Class1")->FirstChildElement("copyItem"); myOtherXMLElement->CopyElement(myXMLElement, afterMyDestinationElement); or myOtherXMLElement->MoveElement(myXMLElement, afterMyDestinationElement); //this deletes tmyXMLElement after copying it.

Is there an existing way to do this? I have tried a few methods, but I have not found something that I can use correctly.

ghost avatar Mar 01 '15 19:03 ghost

Copying can be done with ShallowClone(), but that doesn't copy sub-nodes, and certainly doesn't have the rich functionality you are proposing. I think having a DeepClone() would solve many of these sort of use cases (moving elements between trees), and DeepClone() combined with the existing would at least give the functionality you want.

leethomason avatar Mar 04 '15 23:03 leethomason

Thanks @leethomason, the DeepClone() might be a nice feature for the future!

ghost avatar Mar 12 '15 18:03 ghost

+1 for DeepClone

petko avatar Jun 30 '16 12:06 petko