How to make a deep copy of an entire QDomDocument

I want to create a deep copy QDomDocument

in an xml model to allow the user to restore the document to its original state later. The QDomDocument documentation says this can be achieved using cloneNode()

. However, it cloneNode()

returns QDomNode

, not QDomDocument

, and I can't figure out how to properly add it to a new document.

I tried:

QDomDocument copy;
copy.importNode(existingDocument.cloneNode(true),true);

      

and

QDomDocument copy;
copy.appendChild(existingDocument.cloneNode(true),true);

      

but doesn't work.

+3


source to share


1 answer


If you have a QDomNode, you can use the toDocument function .

Assuming the QDomNode node is the node returned from cloneNode ()



QDomDocument newDocument = node.toDocument();

      

+2


source







All Articles