Hi All, I need duplicate node (in same document). How to I
can get this? Sample: I have this: ------------------------------------------------- <ct> <product> <generalinfo> </generalinfo> <rawmaterials> </rawmaterials> <productcontrol> <name>Test</name> </productcontrol> </product> </ct> I duplicate it: (like this) ------------------------------------------------- <ct> <product> <generalinfo> </generalinfo> <rawmaterials> </rawmaterials> <productcontrol> <name>Test</name> </productcontrol> </product> <product> <generalinfo> </generalinfo> <rawmaterials> </rawmaterials> <productcontrol> <name>Test</name> </productcontrol> </product> </ct> I tried this: // m_strNodeNameToClone == Test
//-> <name>Test</name> xercesc_2_6::DOMDocument* pDoc = m_pParser->getDocument(); DOMElement*
pRoot = pDoc->getDocumentElement(); DOMNodeList* pNodeList = pRoot->getElementsByTagName(X("product")); for ( int
i = 0 ;
i <= (int)pNodeList->getLength() - 1
; i++ ) { DOMNode* pProductNode =
pNodeList->item(i); DOMNodeList*
pProductChieldsNodeList
= pProductNode->getChildNodes(); for ( int
i = 0 ;
i <= (int)pProductChieldsNodeList->getLength() - 1
; i++ ) { DOMNode* pNode =
pProductChieldsNodeList->item(i); if(CString(pNode->getNodeName()) == "productcontrol") { DOMNodeList* pProductControlChieldsNodeList = pNode->getChildNodes(); for ( int
i = 0 ;
i <= (int)pProductControlChieldsNodeList->getLength() - 1
; i++ ) { DOMNode* pNode =
pProductControlChieldsNodeList->item(i); if(CString(pNode->getNodeName()) == "name") { if(CString(pNode->getTextContent()) == m_strNodeNameToClone) { //pRoot->appendChild(pProductNode); //pRoot->cloneNode() //pRoot->appendChild(pProductNode->cloneNode(true)); //pDoc->importNode(pProductNode->cloneNode(true),
true); pDoc->appendChild(pDoc->importNode(pProductNode, true)); return; } } } } } } Thanks |
- Re: I need find ans duplicate node. Renato Tegon Forti
- Re: I need find ans duplicate node. Alberto Massari