Al2*_*2O3 2 c++ io tree qt dom
我使用QDomDocument编写XML文档.
但是在我的dom树中,一些节点是使用docA创建的,一些是使用docB创建的.
QDomElement parentNode = docA.CreateElement("name");//created by docA
QDomElement childNode = docB.CreateElement("value");//created by docB
parentNode.appendChild(childNode);//in onr tree
Run Code Online (Sandbox Code Playgroud)
和:
QTextStream out(&file);
docA.save(out, Indent);//docA created the root QDomElement
//write the file using docA
Run Code Online (Sandbox Code Playgroud)
那么可以像这样将整个树写入XML吗?
你应该避免这种情况,因为如果docB仍在使用,如果docA超出范围,事情就会出现问题.我相信你提出的建议在技术上会有效,直到发生这种情况,但图书馆似乎是为了阻止它.
但是,有一个函数QDomDocument :: importNode()可能就是你想要的.你可以这样做:
docAParent.appendChild( docA.importNode( docBNode, true ) );
Run Code Online (Sandbox Code Playgroud)
boolean参数控制是否进行深层复制.
请参阅文档:http://qt-project.org/doc/qt-4.8/qdomdocument.html#importNode