Skip to Content
0
Former Member
Apr 01, 2009 at 10:14 AM

Difference between node.invalidate() and node.removeElement()

213 Views

Hi,

I was going through some code recently and came across the concept of removing the elements from a node to clear the node as a substitute for node.invalidate().

For eg:

If we have a node X which we need to clear, the following is the code user for removing the elements:

CASE 1:

if (wdContext.nodeX() != null && wdContext.nodeX().size() > 0) {

for (int iCtr = (wdContext.X.size() - 1); iCtr >= 0; iCtr--)

wdContext.nodeX().removeElement( wdContext.nodeX().getElementAt(iCtr));

}

CASE 2:

wdContext.nodeX().invalidate();

I am not sure I fully understand how this would help and in what way the two cases would be different. It would be great if someone could throw some light on the same.

Also, as you can see in CASE 1, the if() condition checks for

---> wdContext.nodeX() != null

---> wdContext.nodeX().size() > 0

Wouldn't checking just one of the above conditions be sufficient? How are the 2 conditions different when there are no elements in the node.

Thanks in advance.

Regards,

Priyanka Parmar.