A friend of mine with a one-year-old child lives in a neighbourhood with many aggressive, poorly trained dogs who sometimes get out without a leash. Obviously, the best thing is to avoid a conflict in the first place (e.g. keeping the child away from off-leash dogs, talking to the dogs owners, introducing the child to some of the dogs), but how can my friend prepare for the worst case that a dog attacks the child? Will a dog whistle scare the dog away? Is there something like pepper spray that will affect dogs but not children?
First of all, dogs usually don't attack people or children without being provoked. Many attacks on children happen because the children touch a dog in an uncoordinated way (like poking the eye) or their running and playing triggers the hunting instinct of the dog. Another provocation is entering the territory of the dog.
If the dogs are mostly behind fences and just sometimes escape to the street, there's a low risk that they perceive parts of the street as their territory. I would take a child by the hand or carry them on my arms or shoulders (depending on how scared the child is) and walk on.
If these dogs are on the street most of the time, or they're stray dogs, there's a higher risk they will attack people. However, "attack" means mostly "bark at people", not bite them. I would always carry a child on my shoulders to keep them safely away from the dogs and to avoid flailing or running away. A child is always the easiest target and these dogs know it!
In some places it's usual to carry a stick where aggressive stray dogs live. Usually just carrying the stick is enough to deter any attacks because the dogs don't want to get beaten. In a pinch, anything that looks even remotely like a stick can help, like an umbrella or a newspaper rolled up along the long side.
A more portable alternative is to tie a somewhat heavy object (like a carabiner or a heavy rubber ball) to one end of a rope, dog leash or tape. In case of a dog attack you can start swinging the rope in a circle and smack the dog in the head with the object. Please be very reasonable with the choice of this object. You want to deter an attack, not kill the dog or cause permanent damage.
If you are in the unfortunate situation that a dog is actually attacking you and trying to bite you or the child, the safest option is to climb onto the roof of the nearest car and call for help.
A dog whistle is no proper tool to stop an actual attack. The dog will simply ignore it. Other methods like pepper spray or a loud horn (similar to a Vuvuzela) that can actually stop a dog will also effect the child. This is especially true for "inaudible" whistles or sound emmiters that produce a frequency too high for most adults to hear. Children may still be able to hear them and even if you cannot perceive the sound the sound pressure (loudness) can still damage your own ear.