Although a loud horn is certainly a good idea, I question whether there would be time to 'deploy' it in the fraction of a second it takes to get doored. A couple of thoughts:
As other posters have stated, always ride outside the 'door zone' when parked cars are present - that usually means a minimum of 3 to 4 feet from parked cars; take the lane if you have to. You used to be able to see into cars and trucks and visually ID motorists that might be getting ready to open their door in your path. These days, with tinted windows and higher seatbacks, this visual method is much harder to rely on.
Also, as others have stated, generally it is illegal for a motorist to open a door into traffic without checking first, and they would indeed be at fault for dooring you. Only works if you got the motorist's license # and insurance policy #. Best if a police officer is called to the scene and files an accident report - even better if the officer knows the law and cites the motorist. Having a lawyer or your own insurance company advocating for you will ensure best results and save you from a lot of frustration dealing with the motorist's insurance company on your own.