cancel
Showing results for 
Search instead for 
Did you mean: 

copy context node

Former Member
0 Kudos

Hi all,

how can I copy an element and its subnode elements into another element considering that I cannot use WDCopyService.copyElements neither WDCopyService.copySubtree?

thanks

Stefano

Accepted Solutions (1)

Accepted Solutions (1)

roberto_tagliento
Active Contributor
0 Kudos


wdContext.nodeFrom().moveFirst();
do {
   
   wdContext.nodeTo().add(
           wdContext.nodeTo().createElementTo()
   );  
  wdContext.nodeTo().moveLast();

   wdContext.currentToElement().setATTR(
      wdContext.currentFromElement().getATTR()
   );
  .....

}while( wdContext.nodeFrom().moveNext() != null );



Answers (3)

Answers (3)

Former Member
0 Kudos

Ok, I've solved using iteration and then WDCopy copycorresponding...

many thanks

Stefano

monalisa_biswal
Contributor
0 Kudos

Traverse through Parent Node.

Copy elements of parent node

For each element of parent node traverse throgh child node and copy elements.

wdContext.node<ParentNode>().moveFirst();

do

{

IPrivate<ViewName>.I<ParentTargetNode>Element parentElement=

wdContext.node<ParentTargetNode>().create<ParentTargetNode>Elemen();

wdContext.node<ParentTargetNode>().addElement(parentElement);

wdContext.node<ParentTargetNode>().moveLast();

do

{

IPrivate<viewname>.I<ChildTargetNode>Element ChildElement=

wdContext.node<ChildTargetNode>().create<ChildTargetNode>Element();

wdContext.node<ChildTargetNode>().addElement(ChildElement);

ChildElement.set<attrname>(wdContext.current<ChildNode>Element().get<attrname>());

//

}while(wdContext.node<ChildNode>().moveNext()!=null);

}while(wdContext.node<ParentNode>().moveNext()!=null);

Former Member
0 Kudos

Hi,

If u wanna copy so, i think u've to loop thru the node and set the values manually:

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

{

... wdContext.nodeDest().addElement(i, wdContext.nodeDest().createElement());

... wdContext.nodeDest().getDestElementAt(i).setAtt(wdContext.nodeSource().getSourceElementAt(i).getAtt());

}

// same can be followed to sub nodes also

Regards,

Aparna .P