void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument) const
{
- m_dom=dom;
- if (dom) {
- if (bindDocument) {
- setDocument(dom->getOwnerDocument());
- }
+ m_dom = dom;
+ if (dom && bindDocument) {
+ DOMDocument* doc = dom->getOwnerDocument();
+ setDocument(doc);
+ DOMElement* documentRoot = doc->getDocumentElement();
+ if (!documentRoot)
+ doc->appendChild(dom);
+ else if (documentRoot != dom)
+ doc->replaceChild(dom, documentRoot);
}
}