You can loop through each object in the hierarchy using things like nodes.length. Email me if you'd like a better explanation and some sample script showing how to do that.
Also, I know that I sent you a better solution, but I noticed something revisiting this post. Using "x.rawValue.length == 0" is probably not the best way to go. If "x.rawValue" is null, "x.rawValue.length" will be undefined and so, your script will not enter the "if" statement. Use "x.rawValue == null" instead.