At 11.18 02/02/2005 -0200, Renato Tegon Forti wrote:
Hi All,

I need duplicate node (in same document). How to I can get this?

Why don't you just do

  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);
    pRoot->appendChild(pProductNode->cloneNode(true));
  }

Alberto


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



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to