C++ xerces_3_1 adoptNode()方法返回NULL

C++ xerces_3_1 adoptNode()方法返回NULL,c++,dom,xerces,ownership,xerces-c,C++,Dom,Xerces,Ownership,Xerces C,我目前正在visual studio 2010中使用xerces 3.1 我已经写了这段(非常简单的)代码: XMLPlatformUtils::Initialize(); DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"XML 1.0"); DOMDocument* doc1 = impl->createDocument(L"nsURI", L"abc:root1", 0); DOM

我目前正在visual studio 2010中使用xerces 3.1

我已经写了这段(非常简单的)代码:

XMLPlatformUtils::Initialize();
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"XML 1.0");

DOMDocument* doc1 = impl->createDocument(L"nsURI", L"abc:root1", 0);
DOMDocument* doc2 = impl->createDocument(0, L"root2", 0);
DOMElement* root1 = doc1->getDocumentElement();
DOMElement* root2 = doc2->getDocumentElement();

DOMElement* el1 = doc1->createElement(L"el1");
root1->appendChild(el1);

DOMNode* tmpNode = doc2->adoptNode(el1);    //tmpNode is null after this line
root2->appendChild(tmpNode);

doc1->release();
doc2->release();
xercesc::XMLPlatformUtils::Terminate();
问题是,无论发生什么情况,
adoptNode(…)
方法都将始终返回空指针。我真的不明白这里发生了什么,请帮帮我


PS:我知道我可以使用
importNode(…)
方法从旧文档中删除并释放旧节点,但我希望有一种方法可以解决我的
adoptNode(…)
问题

xerces api为
adoptNode(DOMNode*source)
声明了以下内容:

更改节点、其子节点以及附加属性节点(如果有)的所有者文档

经过一些研究之后,我查看了xerces 3.1中adoptNode的实现,不幸的是这是不可能的。引用源代码:

if(sourceNode->getOwnerDocument()!=this)
{
    // cannot take ownership of a node created by another document, as it comes from its memory pool
    // and would be delete when the original document is deleted
    return 0;
}
编辑

这种方法有一个变通方法,但它需要一些DOM实现的知识(特别是在使用UserData时)。您可以使用
importNode(…)
导入节点,并从旧文档中删除另一个节点

为了不浪费内存,应该释放旧节点

如果已将userdata附加到旧节点,则新文档必须具有一些
UserDataHandler
,它将userdata从旧节点应用到新节点

请注意,旧节点上的可能引用现在不会指向新节点。它们必须手动更改(或使用一些UserDataHandler解决方案)