简体   繁体   English

如何制作整个QDomDocument的深层副本

[英]How to make a deep copy of an entire QDomDocument

I want to create a deep copy of a QDomDocument in an xml model in order to allow the user to later restore the document to its original state. 我想在xml模型中创建QDomDocument的深层副本,以便用户以后可以将文档还原到其原始状态。 The QDomDocument documentation says that this can be achieved by using cloneNode() . QDomDocument文档说这可以通过使用cloneNode()来实现。 However, cloneNode() returns a QDomNode , not a QDomDocument , and I can't seem to figure out how how to properly add it to a new document. 但是, cloneNode()返回一个QDomNode ,而不是QDomDocument ,我似乎无法弄清楚如何正确地将它添加到新文档。

I've tried: 我试过了:

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

and

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

but neither work. 但都没有工作。

If you have a QDomNode, you can use its toDocument function. 如果您有QDomNode,则可以使用其toDocument函数。

Assuming QDomNode node is the node returned from cloneNode() 假设QDomNode节点是cloneNode()返回的节点

QDomDocument newDocument = node.toDocument();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM