cancel
Showing results for 
Search instead for 
Did you mean: 

How to use copySubTree in WDCopyService

Amey-Mogare
Contributor
0 Kudos

Hi,

I want to copy node elements from node-1 to node-2..

These two node has exactly same structure. These node have child nodes like following:-

Node 'Transaction' has two value attributes-> 'tid', 'tname' and a value node 'Combination' which has a value attribute 'desc'

Im able to copy value attributes tid, tname using copyCorresponding, but how do I copy child node elements ???

Regards,

Amey

Edited by: Amey Mogare on Feb 13, 2008 7:26 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you can use copySubTree(source,target) of WDCopyService

Regards,

Sudhir

Amey-Mogare
Contributor
0 Kudos

Ya, i can use copySubTree()...

But I m not able to get how it works??

I read this from its documentation-->

-


copySubtree

public static void copySubtree(IWDNode source,

IWDNode target)

Copies all elements from to complete subtree of source to target. This is done by applying copyElements(IWDNode, IWDNode) to the nodes and then searching for equally named subnodes and recursively applying copySubtree to them.

Parameters:

source - The source node

target - The target node

Throws:

WDRuntimeException - if copyElements(IWDNode, IWDNode) fails for a node in the subtree.

-


I tried in several ways, but it is not working.. can u giv me any sample code to copy subtree???

Regards,

Amey

Former Member
0 Kudos

Hi,

Did the above code worked?Or let me know in what way you have implemented it.

Regards,

Sudhir

Amey-Mogare
Contributor
0 Kudos

Hiiii Sudhir,

I guess there is something wrong in my implementation:-

Bcoz it is only copying 1st element's subtree..I tried putting it in loop too, but still not working..

public boolean BackUpTransaction( )

{

wdContext.nodeTransaction_1().invalidate();

try{

//Master = Transaction

//Target = Transaction_1

IPrivateView1.ITransaction_1Node TargetNode = wdContext.nodeTransaction_1();

IPrivateView1.ITransactionNode masterNode = wdContext.nodeTransaction();

int size = masterNode.size();

for (int i = 0; i < size; i++)

{

//Copying Transaction's value attributes

IPrivateView1.ITransactionElement masterElement = (IPrivateView1.ITransactionElement)wdContext.nodeTransaction().getElementAt(i);

IPrivateView1.ITransaction_1Node tr1node = wdContext.nodeTransaction_1();

IPrivateView1.ITransaction_1Element tr1element = tr1node.createTransaction_1Element();

WDCopyService.copyCorresponding(masterElement, tr1element);

tr1node.addElement(tr1element);

} //end of for

WDCopyService.copySubtree(wdContext.nodeTransaction().nodeCombination(),wdContext.nodeTransaction_1().nodeCombination_1());

} //end of try

catch(Exception e)

{

e.printStackTrace();

}

return true;

} //end of function

Pls suggest !!!

thank you..

Regards,

Amey

Former Member
0 Kudos

Hi,

This should diffinetly work

WDCopyService.copyElements(wdContext.nodeMain(),wdContext.nodeMain_1());

for(int k=0;k<size;k++){

IMainElement ele=wdContext.nodeMain().getMainElementAt(k);

IMain_1Element ele1=wdContext.nodeMain_1().getMain_1ElementAt(k);

WDCopyService.copyElements(ele.nodeSub(),ele1.nodeSub_1());

}

Regards,

Sudhir

Edited by: Sudhir Gorantla on Feb 15, 2008 7:07 AM

Former Member
0 Kudos

public boolean BackUpTransaction( )

{

wdContext.nodeTransaction_1().invalidate();

try{

//Master = Transaction

//Target = Transaction_1

IPrivateView1.ITransaction_1Node TargetNode = wdContext.nodeTransaction_1();

IPrivateView1.ITransactionNode masterNode = wdContext.nodeTransaction();

int size = masterNode.size();

WDCopyService.copyElements(masterNode,TargetNode);

for (int i = 0; i < size; i++)

{

WDCopyService.copyElements(masterNode.getElementAt(i).nodeCombination(),TargetNode.getElementAt(i).nodeCombination_1());

} //end of for

} //end of try

catch(Exception e)

{

e.printStackTrace();

}

return true;

} //end of function

Regards,

Sudhir

Edited by: Sudhir Gorantla on Feb 15, 2008 7:13 AM

Former Member
0 Kudos

Have you tried it?

Regards,

Sudhir

Amey-Mogare
Contributor
0 Kudos

yes sudhir. It worked.

Thanks a lot for this..

Regards,

Amey

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You can try this

WDCopyService.copyElements(wdContext.nodeTransaction(),wdContextNodeTransaction_1());

WDCopyService.copySubTree(wdContext.nodeTransaction().nodeCombination(),wdContext.nodeTransaction_1().nodeCombination());

Regards,

Sudhir