Are you sure you can't get the name of the tag without looping through all previous nodes?