cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete elements of a node

Former Member
0 Kudos

Hi All,

I want to delete elements of a node.

Can someone tell me how to do it. Please provide some sample code.

Regards

Nikhil Bansal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

No Problem : here it is:

// loop backwards to avoid index troubles

for (int ld_i = ld_n - 1; ld_i >= 0; --ld_i) {

wdContext.nodeInputItemCond_Val().removeElement(wdContext.nodeInputItemCond_Val().getElementAt(ld_i));

}//endfor

Edited by: Armin Reichert on Feb 13, 2008 7:48 PM

Former Member
0 Kudos

Hi Christian,

Thanks for the reply.

Rewarding full points to you.

Just 1 ques :

Why do I have to loop backwards. I mean why can't i start with index 0 and start deleting.

Regards

Nikhil

Former Member
0 Kudos

The node reorganizes it's elements when you delete an element: If you delete the element at index 0, a new element will be sitting at index 0. Thus, if you'd loop forward, you'd only delete half of the elements (skipping 1 with every loop) and probably even getting an exception when you have processed half of the elements, since you'll then be requesting an element index that does not exist anymore.

If you need to delete all elements of a node, the invalidate() method is the way to go though.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

An easier way would be to just invalidate the node. If you have a node called Test under the root, then clear all element list by :

wdContext.nodeTest().invalidate();

Regards,

Satyajit.