deep copy and clone
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index e9b275b..819382b 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -771,6 +771,18 @@
}
}
+XMLNode* XMLNode::DeepClone(XMLDocument* document) const
+{
+ XMLNode* clone = this->ShallowClone(document);
+ if (!clone) return 0;
+
+ for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) {
+ XMLNode* childClone = child->DeepClone(document);
+ TIXMLASSERT(childClone);
+ clone->InsertEndChild(childClone);
+ }
+ return clone;
+}
void XMLNode::DeleteChildren()
{
@@ -2006,6 +2018,17 @@
}
+void XMLDocument::DeepCopy(XMLDocument* target)
+{
+ TIXMLASSERT(target);
+ TIXMLASSERT(target != this);
+
+ target->Clear();
+ for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) {
+ target->InsertEndChild(node->DeepClone(target));
+ }
+}
+
XMLElement* XMLDocument::NewElement( const char* name )
{
TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() );