From: Alberto M. <ama...@us...> - 2006-07-19 20:42:37
|
Update of /cvsroot/xqilla/xqilla/src/context/impl In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30726/src/context/impl Modified Files: ItemFactoryImpl.cpp Log Message: Added cloneNode API to ItemFactory; global variables exported by a module containing nodes must be imported by copying the nodes, or they will be pointing to deleted documents Index: ItemFactoryImpl.cpp =================================================================== RCS file: /cvsroot/xqilla/xqilla/src/context/impl/ItemFactoryImpl.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ItemFactoryImpl.cpp 23 Jun 2006 17:39:18 -0000 1.14 --- ItemFactoryImpl.cpp 19 Jul 2006 20:42:32 -0000 1.15 *************** *** 64,67 **** --- 64,106 ---- } + Node::Ptr ItemFactoryImpl::cloneNode(const Node::Ptr node, const DynamicContext *context) const + { + DOMNode* xNode=(DOMNode*)node->getInterface(Node::gXerces); + assert(xNode!=NULL); + if(xNode->getNodeType()==DOMNode::DOCUMENT_NODE) + { + DOMDocument *document = context->createNewDocument(); + + DOMNode* child=xNode->getFirstChild(); + while(child) + { + DOMNode *newChild = document->importNode(child,true); + if(child->getNodeType()==DOMNode::ELEMENT_NODE) + XPath2Utils::copyElementType(document, (DOMElement*)newChild, (const DOMElement*)child); + if(context->getDebugCallback()) context->getDebugCallback()->ReportClonedNode(const_cast<DynamicContext*>(context), child, newChild); + document->appendChild(newChild); + child=child->getNextSibling(); + } + return new NodeImpl(document, context); + } + else if(xNode->getNodeType()==DOMXPathNamespace::XPATH_NAMESPACE_NODE) + { + // TODO + XQThrow(ASTException,X("ItemFactoryImpl::cloneNode"),X("Cannot clone a namespace node")); + return NULL; + } + else + { + DOMDocument* mainDoc=getOutputDocument(context); + DOMNode* newNode=mainDoc->importNode(xNode, true); + if(xNode->getNodeType()==DOMNode::ATTRIBUTE_NODE) + XPath2Utils::copyAttributeType(mainDoc, (DOMAttr*)newNode, (const DOMAttr*)xNode); + else if(xNode->getNodeType()==DOMNode::ELEMENT_NODE) + XPath2Utils::copyElementType(mainDoc, (DOMElement*)newNode, (const DOMElement*)xNode); + if(context->getDebugCallback()) context->getDebugCallback()->ReportClonedNode(const_cast<DynamicContext*>(context), xNode, newNode); + return new NodeImpl(newNode, context); + } + } + Node::Ptr ItemFactoryImpl::createTextNode(const XMLCh *value, const DynamicContext *context) const { |