You can train a dog or cat to change its behaviour patterns, but to do this successfully you should have a well thought out training program which is logical, consistent and ongoing. There are many good reference books available on the subject and numerous websites on the Internet offering advice and guidance. Remember, firstly, that you must punish or reward within a few seconds of the event, otherwise the animal will not be able to associate effect with cause. And secondly, training dogs and cats is all about repetition and reinforcement, so persistence is definitely the key to success. Dogs and cats have a sense of smell which is 100's of times stronger than that of a human.
Smells play a very important part in the animal's life.
It is normal behaviour for dogs and cats to mark out their territory with urine or faeces. It also brings a dog or cat back to the same spot for repeat visits. They won't urinate near their food or sleeping basket. So if you have problems with dogs and cats messing in your garden, the first step is to remove any droppings and carefully wash away any urine. This should be done as soon as possible after the event.