public boolean testExpression(String expression, int startingStackDepth) {
        if (expression.equals(".")) return true;

        int index = -1;
        while ((index = expression.indexOf("/", index + 1)) > -1) {
            // Don't consider attributes a new depth level
            if (expression.charAt(index + 1) != '@') {
                startingStackDepth++;
            }
        }


        return (startingStackDepth == getCurrentDepth()
                && stackString.endsWith("/" + expression));
    }
Tests the specified expression against the current position in the XML
document being parsed, and restricts the expression to matching at the
specified stack depth.

@param expression
           The psuedo-xpath expression to test.
@param startingStackDepth
           The depth in the stack representing where the expression must
           start matching in order for this method to return true.

@return True if the specified expression matches the current position in
        the XML document, starting from the specified depth.
aws-java-sdk-core/src/main/java/com/amazonaws/transform/StaxUnmarshallerContext.java