In many cases towns and cities have unconstitutional laws on their books. For example, recently the Supreme Court ruled that blanket give-all-records-to-police hotel ordinances were unconstitutional. Nevertheless, many cities and town have ordinances that require hotels to record extensive information on all their guests and to allow police to search those records whenever the police want without a warrant or even notice of any kind.
So, the question is how can a hotel challenge such ordinances and have them voided by the courts without breaking them and criminalizing themselves?
Update: I found an article on this subject dating back to 1967 (Declaratory Relief in the Criminal Law, Harvard Law Review, Vol. 80, No. 7 (May, 1967), pp. 1490-1513 (24 pages)). So, answers to this question could be seen as modern extensions to this paper with specific emphasis on civil or regulatory law (not criminal and not private).