My general rule is that if you are calling getParent, your code is too complicated.

You would not have to call getParent if you detected when the CHILD node is the scan that you want and the "rootNode" is the parent.
This is more efficient -- if you reach a child that is a scanNode but the wrong scanNode, you just skip it without recursion or getting its child count.